Perl/Lint/Policy/BuiltinFunctions/ProhibitVoidMap.pm

filter: Statementstmt 32.6% 16 / 49 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 1 totaltotal 20.1% 21 / 104 CC 20 SCAR 58.2
CC
20
Cov
18%
evaluate
420.0
BEGIN
1.0
BEGIN
1.0
CRAP 336.2
« Perl/Lint/Policy/ControlStructures/ProhibitDeepNests.pm ↑ Summary Perl/Lint/Policy/Variables/ProhibitMatchVars.pm »
1 package Perl::Lint::Policy::BuiltinFunctions::ProhibitVoidMap;
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 => '"map" used in void context',
11 EXPL => 'Use a "for" loop instead',
12 2 };
13  
14 0 ▶sub evaluate {
Subroutine evaluate: not called CC=20 SCAR=60.4
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_before_comma = 0; # XXX to decide is in context or not
20 0 my $is_in_map = 0;
21 0 my $is_in_ctrl_statement = 0;
22 0 my $left_brace_num = 0;
23 0 ▶ for (my $i = 0; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
24 0 my $token_type = $token->{type};
25 0 my $token_data = $token->{data};
26 0 ▶ if ($token_type == BUILTIN_FUNC) {
Branch: 6 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
elsif ($token_type == 104) { } 0 0 0
27 0 ▶ if ($token_data eq 'map') {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_data eq "map") 0 0 0
28 0 ▶ next if $is_in_map;
Branch: 1 branch
BranchTrueFalseTotal
if $is_in_map 0 0 0
29  
30 0 ▶ if ($is_in_ctrl_statement) {
Branch: 2 branches
BranchTrueFalseTotal
if ($is_in_ctrl_statement) { } 0 0 0
elsif (not $is_in_context || $is_before_comma) { } 0 0 0
31 0 ▶ if ($left_brace_num) {
Branch: 1 branch
BranchTrueFalseTotal
if ($left_brace_num) 0 0 0
32 push @violations, {
33 filename => $file,
34 line => $token->{line},
35 0 description => DESC,
36 explanation => EXPL,
37 policy => __PACKAGE__,
38 };
39 }
40 }
41 ▶ elsif (!$is_in_context && !$is_before_comma) {
Condition0%0/3
$is_in_context || $is_before_comma
l!l&&r!l&&!r
000
MC/DC0%0/2
$is_in_context || $is_before_comma
$is_in_context $is_before_comma
Truth table0%0/3
A || B
A= $is_in_contextB= $is_before_comma
ABresult
1X1
011
000
42 push @violations, {
43 filename => $file,
44 line => $token->{line},
45 0 description => DESC,
46 explanation => EXPL,
47 policy => __PACKAGE__,
48 };
49 }
50  
51 0 $is_in_map = 1;
52 0 next;
53 }
54 0 $is_in_context = 1;
55 }
56 elsif ($token_type == ASSIGN) {
57 0 $is_in_context = 1;
58 }
59 ▶ 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
60 $token_type == IF_STATEMENT ||
61 $token_type == FOR_STATEMENT ||
62 $token_type == WHILE_STATEMENT ||
63 $token_type == UNLESS_STATEMENT
64 ) {
65 0 $is_in_ctrl_statement = 1;
66 }
67 elsif ($is_in_ctrl_statement) {
68 0 ▶ if ($token_type == LEFT_BRACE) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 109) { } 0 0 0
elsif ($token_type == 110) { } 0 0 0
69 0 $left_brace_num++;
70 }
71 elsif ($token_type == RIGHT_BRACE) {
72 0 $left_brace_num--;
73 0 ▶ if ($left_brace_num <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($left_brace_num <= 0) 0 0 0
74 0 $is_in_ctrl_statement = 0;
75 0 $is_in_map = 0;
76 }
77 }
78 }
79 elsif ($token_type == SEMI_COLON) {
80 0 $is_in_context = 0;
81 0 $is_in_map = 0;
82 }
83 elsif ($token_type == COMMA) {
84 0 $is_before_comma = 1;
85 }
86 else {
87 0 $is_before_comma = 0;
88 }
89 }
90  
91 0 return \@violations;
92 }
93  
94 2 1;
95  
« Perl/Lint/Policy/ControlStructures/ProhibitDeepNests.pm ↑ Summary Perl/Lint/Policy/Variables/ProhibitMatchVars.pm »