Perl/Lint/Policy/Variables/ProhibitConditionalDeclarations.pm

filter: Statementstmt 38.1% 16 / 42 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 1 totaltotal 21.8% 21 / 96 CC 17 SCAR 54.7
CC
17
Cov
20%
evaluate
306.0
BEGIN
1.0
BEGIN
1.0
CRAP 236.7
« Perl/Lint/Policy/CodeLayout/ProhibitParensWithBuiltins.pm ↑ Summary Perl/Lint/Policy/ValuesAndExpressions/ProhibitQuotesAsQuotelikeOperatorDelimiters.pm »
1 package Perl::Lint::Policy::Variables::ProhibitConditionalDeclarations;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Perl::Lint::Constants::Type;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use parent "Perl::Lint::Policy";
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 DESC => q{Variable declared in conditional statement},
9 EXPL => q{Declare variables outside of the condition},
10 2 };
11  
12 0 ▶sub evaluate {
Subroutine evaluate: not called CC=17 SCAR=57.2
Pod undocumented
13 0 my ($class, $file, $tokens) = @_;
14  
15 0 my @violations;
16 0 my $token_num = scalar @$tokens;
17 0 ▶ for (my $i = 0; $i < $token_num; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $token_num) 0 0 0
18 0 my $token = $tokens->[$i];
19 0 my $token_type = $token->{type};
20  
21 0 ▶ if ($token_type == VAR_DECL || $token_type == OUR_DECL) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 62 or $token_type == 91) 0 0 0
Condition0%0/3
$token_type == 62 or $token_type == 91
l!l&&r!l&&!r
000
MC/DC0%0/2
$token_type == 62 or $token_type == 91
$token_type == 62 $token_type == 91
Truth table0%0/3
A or B
A= $token_type == 62B= $token_type == 91
ABresult
1X1
011
000
22 0 ▶ for ($i++; $i < $token_num; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $token_num) 0 0 0
23 0 $token = $tokens->[$i];
24  
25 0 ▶ if ($token->{type} == ASSIGN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->{"type"} == 65) 0 0 0
26 0 my $is_before_right_paren = 0;
27 0 ▶ for ($i++; $i < $token_num; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $token_num) 0 0 0
28 0 $token = $tokens->[$i];
29 0 $token_type = $token->{type};
30  
31 0 ▶ if ($token_type == RIGHT_PAREN) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 108) { } 0 0 0
elsif ($token_type == 96 or $token_type == 99 or $token_type == 132 or $token_type == 133 or $token_type == 134) { } 0 0 0
32 0 $is_before_right_paren = 1;
33 }
34 ▶ elsif (
Condition0%0/12
$token_type == 96 or $token_type == 99 or $token_type == 132 or $token_type == 133 or $token_type == 134
l!l&&r!l&&!r
000
$token_type == 96 or $token_type == 99 or $token_type == 132 or $token_type == 133
l!l&&r!l&&!r
000
$token_type == 96 or $token_type == 99 or $token_type == 132
l!l&&r!l&&!r
000
$token_type == 96 or $token_type == 99
l!l&&r!l&&!r
000
MC/DC0%0/5
$token_type == 96 or $token_type == 99 or $token_type == 132 or $token_type == 133 or $token_type == 134
$token_type == 96 $token_type == 99 $token_type == 132 $token_type == 133 $token_type == 134
Truth table0%0/6
A or B or C or D or E
A= $token_type == 96B= $token_type == 99C= $token_type == 132D= $token_type == 133E= $token_type == 134
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
35 $token_type == IF_STATEMENT ||
36 $token_type == UNLESS_STATEMENT ||
37 $token_type == WHILE_STATEMENT ||
38 $token_type == FOR_STATEMENT ||
39 $token_type == FOREACH_STATEMENT
40 ) {
41 push @violations, {
42 filename => $file,
43 line => $token->{line},
44 0 description => DESC,
45 explanation => EXPL,
46 policy => __PACKAGE__,
47 };
48 0 last;
49 }
50 else {
51 0 my $_is_before_right_paren = $is_before_right_paren;
52 0 $is_before_right_paren = 0;
53 0 ▶ if ($_is_before_right_paren && $token_type == LEFT_BRACE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_is_before_right_paren and $token_type == 109) 0 0 0
Condition0%0/3
$_is_before_right_paren and $token_type == 109
!ll&&!rl&&r
000
MC/DC0%0/2
$_is_before_right_paren and $token_type == 109
$_is_before_right_paren $token_type == 109
Truth table0%0/3
A and B
A= $_is_before_right_parenB= $token_type == 109
ABresult
0X0
100
111
54 0 last;
55 }
56 }
57  
58 0 ▶ last if $token->{type} == SEMI_COLON;
Branch: 1 branch
BranchTrueFalseTotal
if $token->{"type"} == 106 0 0 0
59 }
60 0 last;
61 }
62  
63 0 ▶ last if $token->{type} == SEMI_COLON;
Branch: 1 branch
BranchTrueFalseTotal
if $token->{"type"} == 106 0 0 0
64 }
65 }
66 }
67  
68 0 return \@violations;
69 }
70  
71 2 1;
72  
« Perl/Lint/Policy/CodeLayout/ProhibitParensWithBuiltins.pm ↑ Summary Perl/Lint/Policy/ValuesAndExpressions/ProhibitQuotesAsQuotelikeOperatorDelimiters.pm »