Perl/Lint/Policy/BuiltinFunctions/ProhibitVoidGrep.pm

filter: Statementstmt 34.7% 16 / 46 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 1 totaltotal 22.3% 21 / 94 CC 18 SCAR 55.9
CC
18
Cov
19%
evaluate
342.0
BEGIN
1.0
BEGIN
1.0
CRAP 267.9
« Perl/Lint/Policy/Modules/RequireVersionVar.pm ↑ Summary Perl/Lint/Policy/CodeLayout/ProhibitParensWithBuiltins.pm »
1 package Perl::Lint::Policy::BuiltinFunctions::ProhibitVoidGrep;
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 # TODO REFACTOR!!!
8  
9 2 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 DESC => '"grep" used in void context',
11 EXPL => 'Use a "for" loop instead',
12 2 };
13  
14 0 ▶sub evaluate {
Subroutine evaluate: not called CC=18 SCAR=58.3
Pod undocumented
15 0 my ($class, $file, $tokens, $args) = @_;
16  
17 0 my @violations;
18 0 my $is_in_context = 0;
19 0 my $is_in_grep = 0;
20 0 my $is_in_ctrl_statement = 0;
21 0 my $left_brace_num = 0;
22 0 ▶ for (my $i = 0; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
23 0 my $token_type = $token->{type};
24 0 my $token_data = $token->{data};
25 0 ▶ if ($token_type == BUILTIN_FUNC) {
Branch: 5 branches
BranchTrueFalseTotal
if ($token_type == 70) { } 0 0 0
elsif ($token_type == 65) { } 0 0 0
elsif ($token_type == 96 or $token_type == 133 or $token_type == 132 or $token_type == 99) { } 0 0 0
elsif ($is_in_ctrl_statement) { } 0 0 0
elsif ($token_type == 106) { } 0 0 0
26 0 ▶ if ($token_data eq 'grep') {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_data eq "grep") 0 0 0
27 0 ▶ next if $is_in_grep;
Branch: 1 branch
BranchTrueFalseTotal
if $is_in_grep 0 0 0
28  
29 0 ▶ if ($is_in_ctrl_statement) {
Branch: 2 branches
BranchTrueFalseTotal
if ($is_in_ctrl_statement) { } 0 0 0
elsif (not $is_in_context) { } 0 0 0
30 0 ▶ if ($left_brace_num) {
Branch: 1 branch
BranchTrueFalseTotal
if ($left_brace_num) 0 0 0
31 push @violations, {
32 filename => $file,
33 line => $token->{line},
34 0 description => DESC,
35 explanation => EXPL,
36 policy => __PACKAGE__,
37 };
38 }
39 }
40 elsif (!$is_in_context) {
41 push @violations, {
42 filename => $file,
43 line => $token->{line},
44 0 description => DESC,
45 explanation => EXPL,
46 policy => __PACKAGE__,
47 };
48 }
49  
50 0 $is_in_grep = 1;
51 0 next;
52 }
53 0 $is_in_context = 1;
54 }
55 elsif ($token_type == ASSIGN) {
56 0 $is_in_context = 1;
57 }
58 ▶ elsif ( # NOTE enough?
Condition0%0/9
$token_type == 96 or $token_type == 133 or $token_type == 132 or $token_type == 99
l!l&&r!l&&!r
000
$token_type == 96 or $token_type == 133 or $token_type == 132
l!l&&r!l&&!r
000
$token_type == 96 or $token_type == 133
l!l&&r!l&&!r
000
MC/DC0%0/4
$token_type == 96 or $token_type == 133 or $token_type == 132 or $token_type == 99
$token_type == 96 $token_type == 133 $token_type == 132 $token_type == 99
Truth table0%0/5
A or B or C or D
A= $token_type == 96B= $token_type == 133C= $token_type == 132D= $token_type == 99
ABCDresult
1XXX1
01XX1
001X1
00011
00000
59 $token_type == IF_STATEMENT ||
60 $token_type == FOR_STATEMENT ||
61 $token_type == WHILE_STATEMENT ||
62 $token_type == UNLESS_STATEMENT
63 ) {
64 0 $is_in_ctrl_statement = 1;
65 }
66 elsif ($is_in_ctrl_statement) {
67 0 ▶ if ($token_type == LEFT_BRACE) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 109) { } 0 0 0
elsif ($token_type == 110) { } 0 0 0
68 0 $left_brace_num++;
69 }
70 elsif ($token_type == RIGHT_BRACE) {
71 0 $left_brace_num--;
72 0 ▶ if ($left_brace_num <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($left_brace_num <= 0) 0 0 0
73 0 $is_in_ctrl_statement = 0;
74 0 $is_in_grep = 0;
75 }
76 }
77 }
78 elsif ($token_type == SEMI_COLON) {
79 0 $is_in_context = 0;
80 0 $is_in_grep = 0;
81 }
82 }
83  
84 0 return \@violations;
85 }
86  
87 2 1;
88  
« Perl/Lint/Policy/Modules/RequireVersionVar.pm ↑ Summary Perl/Lint/Policy/CodeLayout/ProhibitParensWithBuiltins.pm »