Perl/Lint/Policy/ControlStructures/ProhibitCStyleForLoops.pm

filter: Statementstmt 97.3% 36 / 37 Branchbran 72.2% 13 / 18 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 86.7% 59 / 68 CC 11 SCAR 20.7
CC
11
Cov
88%
evaluate
11.7
BEGIN
1.0
BEGIN
1.0
CRAP 7.9
« Perl/Lint/Policy/Miscellanea/ProhibitFormats.pm ↑ Summary Perl/Lint/Policy/ValuesAndExpressions/ProhibitEscapedCharacters.pm »
1 package Perl::Lint::Policy::ControlStructures::ProhibitCStyleForLoops;
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 Perl::Lint::Constants::Kind;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use parent "Perl::Lint::Policy";
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 DESC => 'C-style "for" loop used',
10 EXPL => [100],
11 3 };
12  
13 2 ▶sub evaluate {
Subroutine evaluate: called CC=11 SCAR=24.6
Pod undocumented
14 2 my ($class, $file, $tokens, $src, $args) = @_;
15  
16 2 my @violations;
17 2 ▶ for (my $i = 0; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 38 2 40
18 38 my $token_type = $token->{type};
19  
20 38 ▶ if ($token_type == FOR_STATEMENT || $token_type == FOREACH_STATEMENT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 133 or $token_type == 134) 1 37 38
Condition66%2/3
$token_type == 133 or $token_type == 134
l!l&&r!l&&!r
1037
MC/DC50%1/2
$token_type == 133 or $token_type == 134
$token_type == 133 $token_type == 134
Truth table66%2/3
A or B
A= $token_type == 133B= $token_type == 134
ABresult
1X1
011
000
21 1 my $token = $tokens->[++$i];
22 1 ▶ if ($token->{type} == LEFT_PAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->{"type"} == 107) 1 0 1
23 1 my $semi_colon_count = 0;
24 1 my $left_paren_num = 1;
25 1 ▶ for ($i++; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 12 0 12
26 12 my $token_type = $token->{type};
27 12 ▶ if ($token_type == LEFT_PAREN) {
Branch: 3 branches
BranchTrueFalseTotal
if ($token_type == 107) { } 0 12 12
elsif ($token_type == 108) { } 1 11 12
elsif ($token_type == 106) { } 2 9 11
28 0 $left_paren_num++;
29 }
30 elsif ($token_type == RIGHT_PAREN) {
31 1 ▶ last if --$left_paren_num <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if --$left_paren_num <= 0 1 0 1
32 }
33 elsif ($token_type == SEMI_COLON) {
34 2 $semi_colon_count++;
35 }
36 }
37  
38 1 ▶ if ($semi_colon_count == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($semi_colon_count == 2) 1 0 1
39 push @violations, {
40 filename => $file,
41 line => $token->{line},
42 1 description => DESC,
43 explanation => EXPL,
44 policy => __PACKAGE__,
45 };
46 }
47 }
48 }
49 }
50  
51 2 return \@violations;
52 }
53  
54 3 1;
55  
« Perl/Lint/Policy/Miscellanea/ProhibitFormats.pm ↑ Summary Perl/Lint/Policy/ValuesAndExpressions/ProhibitEscapedCharacters.pm »