Perl/Lint/Policy/BuiltinFunctions/ProhibitBooleanGrep.pm

filter: Statementstmt 60.7% 34 / 56 Branchbran 28.1% 9 / 32 Conditioncond 27.7% 10 / 36 MC/DCmcdc 0.0% 0 / 19 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 39.3% 59 / 150 CC 29 SCAR 54.3
CC
29
Cov
43%
evaluate
267.9
BEGIN
1.0
BEGIN
1.0
CRAP 228.7
« Perl/Lint/Policy/ValuesAndExpressions/ProhibitQuotesAsQuotelikeOperatorDelimiters.pm ↑ Summary Perl/Lint/Policy/InputOutput/RequireEncodingWithUTF8Layer.pm »
1 package Perl::Lint::Policy::BuiltinFunctions::ProhibitBooleanGrep;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use Perl::Lint::Constants::Type;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use parent "Perl::Lint::Policy";
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 DESC => '"grep" used in boolean context',
9 EXPL => [71, 72],
10 3 };
11  
12 2 ▶sub evaluate {
Subroutine evaluate: called CC=29 SCAR=55.9
Pod undocumented
13 2 my ($class, $file, $tokens, $src, $args) = @_;
14  
15 2 my @violations;
16 2 my $is_grep_called = 0;
17 2 my $is_in_boolean_context = 0;
18 2 my $is_in_numeric_comparison_context = 0;
19 2 ▶ for (my $i = 0; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 51 2 53
20 51 my $token_type = $token->{type};
21  
22 51 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 96 or $token_type == 99 or $token_type == 132 or $token_type == 100) 0 51 51
Condition33%3/9
$token_type == 96 or $token_type == 99 or $token_type == 132 or $token_type == 100
l!l&&r!l&&!r
0051
$token_type == 96 or $token_type == 99 or $token_type == 132
l!l&&r!l&&!r
0051
$token_type == 96 or $token_type == 99
l!l&&r!l&&!r
0051
MC/DC0%0/4
$token_type == 96 or $token_type == 99 or $token_type == 132 or $token_type == 100
$token_type == 96 $token_type == 99 $token_type == 132 $token_type == 100
Truth table20%1/5
A or B or C or D
A= $token_type == 96B= $token_type == 99C= $token_type == 132D= $token_type == 100
ABCDresult
1XXX1
01XX1
001X1
00011
00000
23 $token_type == IF_STATEMENT ||
24 $token_type == UNLESS_STATEMENT ||
25 $token_type == WHILE_STATEMENT ||
26 $token_type == UNTIL_STATEMENT
27 ) {
28 0 $token = $tokens->[++$i];
29 0 $token_type = $token->{type};
30 0 ▶ if ($token_type == LEFT_PAREN) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 107) { } 0 0 0
elsif ($token_type == 70 and $token->{'data'} eq 'grep') { } 0 0 0
31 0 my $is_grep_called = 0;
32 0 my $is_in_numeric_comparison_context = 0;
33  
34 0 my $left_paren_num = 1;
35 0 ▶ for ($i++; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
36 0 $token_type = $token->{type};
37 0 ▶ if ($token_type == EQUAL_EQUAL) {
Branch: 4 branches
BranchTrueFalseTotal
if ($token_type == 31) { } 0 0 0
elsif ($token_type == 107) { } 0 0 0
elsif ($token_type == 108) { } 0 0 0
elsif ($token_type == 70 and $token->{'data'} eq 'grep') { } 0 0 0
38 0 $is_in_numeric_comparison_context = 1;
39 }
40 elsif ($token_type == LEFT_PAREN) {
41 0 $left_paren_num++;
42 }
43 elsif ($token_type == RIGHT_PAREN) {
44 0 ▶ if (--$left_paren_num <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (--$left_paren_num <= 0) 0 0 0
45 0 ▶ if ($is_grep_called && !$is_in_numeric_comparison_context) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_grep_called and not $is_in_numeric_comparison_context) 0 0 0
Condition0%0/3
$is_grep_called and not $is_in_numeric_comparison_context
!ll&&!rl&&r
000
MC/DC0%0/2
$is_grep_called and not $is_in_numeric_comparison_context
$is_grep_called not $is_in_numeric_comparison_context
Truth table0%0/3
A and not(B)
A= $is_grep_calledB= not $is_in_numeric_comparison_context
ABresult
0X0
100
111
46 push @violations, {
47 filename => $file,
48 line => $token->{line},
49 0 description => DESC,
50 explanation => EXPL,
51 policy => __PACKAGE__,
52 };
53 }
54 0 last;
55 }
56 }
57 ▶ elsif ($token_type == BUILTIN_FUNC && $token->{data} eq 'grep') {
Condition0%0/3
$token_type == 70 and $token->{"data"} eq "grep"
!ll&&!rl&&r
000
MC/DC0%0/2
$token_type == 70 and $token->{"data"} eq "grep"
$token_type == 70 $token->{"data"} eq "grep"
Truth table0%0/3
A and B
A= $token_type == 70B= $token->{"data"} eq "grep"
ABresult
0X0
100
111
58 0 $is_grep_called = 1;
59 }
60 }
61 }
62 ▶ elsif ($token_type == BUILTIN_FUNC && $token->{data} eq 'grep') {
Condition0%0/3
$token_type == 70 and $token->{"data"} eq "grep"
!ll&&!rl&&r
000
MC/DC0%0/2
$token_type == 70 and $token->{"data"} eq "grep"
$token_type == 70 $token->{"data"} eq "grep"
Truth table0%0/3
A and B
A= $token_type == 70B= $token->{"data"} eq "grep"
ABresult
0X0
100
111
63 push @violations, {
64 filename => $file,
65 line => $token->{line},
66 0 description => DESC,
67 explanation => EXPL,
68 policy => __PACKAGE__,
69 };
70 }
71  
72 0 next;
73 }
74  
75 51 ▶ if ($token_type == BUILTIN_FUNC && $token->{data} eq 'grep') {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 70 and $token->{"data"} eq "grep") 0 51 51
Condition66%2/3
$token_type == 70 and $token->{"data"} eq "grep"
!ll&&!rl&&r
5010
MC/DC0%0/2
$token_type == 70 and $token->{"data"} eq "grep"
$token_type == 70 $token->{"data"} eq "grep"
Truth table66%2/3
A and B
A= $token_type == 70B= $token->{"data"} eq "grep"
ABresult
0X0
100
111
76 0 $is_grep_called = 1;
77 }
78  
79 51 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 53 or $token_type == 52 or $token_type == 14 or $token_type == 16) 0 51 51
Condition33%3/9
$token_type == 53 or $token_type == 52 or $token_type == 14 or $token_type == 16
l!l&&r!l&&!r
0051
$token_type == 53 or $token_type == 52 or $token_type == 14
l!l&&r!l&&!r
0051
$token_type == 53 or $token_type == 52
l!l&&r!l&&!r
0051
MC/DC0%0/4
$token_type == 53 or $token_type == 52 or $token_type == 14 or $token_type == 16
$token_type == 53 $token_type == 52 $token_type == 14 $token_type == 16
Truth table20%1/5
A or B or C or D
A= $token_type == 53B= $token_type == 52C= $token_type == 14D= $token_type == 16
ABCDresult
1XXX1
01XX1
001X1
00011
00000
80 $token_type == OR ||
81 $token_type == AND ||
82 $token_type == ALPHABET_OR ||
83 $token_type == ALPHABET_AND
84 ) {
85 0 $is_in_boolean_context = 1;
86 }
87  
88 51 ▶ if ($token_type == EQUAL_EQUAL) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 31) 0 51 51
89 0 $is_in_numeric_comparison_context = 1;
90 }
91  
92 51 ▶ if ($token_type == SEMI_COLON) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 106) 11 40 51
93 11 ▶ if ($is_grep_called && $is_in_boolean_context && !$is_in_numeric_comparison_context) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_grep_called and $is_in_boolean_context and not $is_in_numeric_comparison_context) 0 11 11
Condition33%2/6
$is_grep_called and $is_in_boolean_context and not $is_in_numeric_comparison_context
!ll&&!rl&&r
1100
$is_grep_called and $is_in_boolean_context
!ll&&!rl&&r
1100
MC/DC0%0/3
$is_grep_called and $is_in_boolean_context and not $is_in_numeric_comparison_context
$is_grep_called $is_in_boolean_context not $is_in_numeric_comparison_context
Truth table25%1/4
A and B and not(C)
A= $is_grep_calledB= $is_in_boolean_contextC= not $is_in_numeric_comparison_context
ABCresult
0XX0
10X0
1100
1111
94 push @violations, {
95 filename => $file,
96 line => $token->{line},
97 0 description => DESC,
98 explanation => EXPL,
99 policy => __PACKAGE__,
100 };
101 }
102 11 $is_grep_called = 0;
103 11 $is_in_boolean_context = 0;
104 11 $is_in_numeric_comparison_context = 0;
105 11 next;
106 }
107 }
108  
109 2 return \@violations;
110 }
111  
112 3 1;
113  
« Perl/Lint/Policy/ValuesAndExpressions/ProhibitQuotesAsQuotelikeOperatorDelimiters.pm ↑ Summary Perl/Lint/Policy/InputOutput/RequireEncodingWithUTF8Layer.pm »