Perl/Lint/Policy/BuiltinFunctions/ProhibitComplexMappings.pm

filter: Statementstmt 29.0% 16 / 55 Branchbran 0.0% 0 / 36 Conditioncond 0.0% 0 / 14 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 1 totaltotal 17.6% 21 / 119 CC 24 SCAR 62.1
CC
24
Cov
15%
evaluate
600.0
BEGIN
1.0
BEGIN
1.0
CRAP 496.7
« Perl/Lint/Policy/CodeLayout/ProhibitQuotedWordLists.pm ↑ Summary Perl/Lint/Policy/Variables/ProhibitReusedNames.pm »
1 package Perl::Lint::Policy::BuiltinFunctions::ProhibitComplexMappings;
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 => 'Map blocks should have a single statement',
9 EXPL => [113],
10 2 };
11  
12 0 ▶sub evaluate {
Subroutine evaluate: not called CC=24 SCAR=64.0
Pod undocumented
13 0 my ($class, $file, $tokens, $src, $args) = @_;
14  
15 0 ▶ my $max_statements = $args->{prohibit_complex_mappings}->{max_statements} || 1;
Condition0%0/2
$args->{'prohibit_complex_mappings'}{'max_statements'} || 1
l!l
00
MC/DC0%0/1
$args->{'prohibit_complex_mappings'}{'max_statements'} || 1
$args->{'prohibit_complex_mappings'}{'max_statements'}
Truth table0%0/2
A
A= $args->{'prohibit_complex_mappings'}{'max_statements'}
Aresult
11
00
16 0 ▶ if (--$max_statements < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (--$max_statements < 0) 0 0 0
17 0 $max_statements = 0;
18 }
19  
20 0 my @violations;
21 0 my $statements_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  
26 0 ▶ if ($token_type == BUILTIN_FUNC && $token_data eq 'map') {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 70 and $token_data eq "map") 0 0 0
Condition0%0/3
$token_type == 70 and $token_data eq "map"
!ll&&!rl&&r
000
MC/DC0%0/2
$token_type == 70 and $token_data eq "map"
$token_type == 70 $token_data eq "map"
Truth table0%0/3
A and B
A= $token_type == 70B= $token_data eq "map"
ABresult
0X0
100
111
27 0 $token = $tokens->[++$i];
28 0 ▶ if ($token->{type} == LEFT_PAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->{"type"} == 107) 0 0 0
29 0 $token = $tokens->[++$i];
30 }
31  
32 0 ▶ if ($token->{type} != LEFT_BRACE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->{"type"} != 109) 0 0 0
33 0 next;
34 }
35  
36 0 my $left_brace_num = 1;
37 0 my $placed_semi_colon = 0;
38 0 ▶ for ($i++; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
39 0 $token_type = $token->{type};
40 0 ▶ if ($token_type == IF_STATEMENT) {
Branch: 5 branches
BranchTrueFalseTotal
if ($token_type == 96) { } 0 0 0
elsif ($token_type == 87) { } 0 0 0
elsif ($token_type == 106) { } 0 0 0
elsif ($token_type == 109) { } 0 0 0
elsif ($token_type == 110) { } 0 0 0
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 elsif ($token_type == DO) { # skip semi-colons that are in do statement
51 0 $token = $tokens->[++$i];
52 0 ▶ if ($token->{type} == LEFT_BRACE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->{"type"} == 109) 0 0 0
53 0 my $left_brace_num = 1;
54 0 ▶ for ($i++; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
55 0 $token_type = $token->{type};
56 0 ▶ if ($token_type == LEFT_BRACE) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 109) { } 0 0 0
elsif ($token_type == 110) { } 0 0 0
57 0 $left_brace_num++;
58 }
59 elsif ($token_type == RIGHT_BRACE) {
60 0 ▶ last if --$left_brace_num <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if --$left_brace_num <= 0 0 0 0
61 }
62 }
63 }
64 }
65 elsif ($token_type == SEMI_COLON) {
66 0 my $next_token = $tokens->[$i+1];
67 0 my $next_token_type = $next_token->{type};
68 0 $statements_num++;
69 0 ▶ if ($statements_num > $max_statements && ($left_brace_num != 1 || ($next_token_type && $next_token_type != RIGHT_BRACE))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($statements_num > $max_statements and $left_brace_num != 1 || $next_token_type && $next_token_type != 110) 0 0 0
Condition0%0/9
$statements_num > $max_statements and $left_brace_num != 1 || $next_token_type && $next_token_type != 110
!ll&&!rl&&r
000
$left_brace_num != 1 or $next_token_type and $next_token_type != 110
l!l&&r!l&&!r
000
$next_token_type and $next_token_type != 110
!ll&&!rl&&r
000
MC/DC0%0/4
$statements_num > $max_statements and $left_brace_num != 1 || $next_token_type && $next_token_type != 110
$statements_num > $max_statements $left_brace_num != 1 $next_token_type $next_token_type != 110
Truth table0%0/5
A and B or C and D
A= $statements_num > $max_statementsB= $left_brace_num != 1C= $next_token_typeD= $next_token_type != 110
ABCDresult
0XXX0
100X0
10100
11XX1
10111
70 push @violations, {
71 filename => $file,
72 line => $token->{line},
73 0 description => DESC,
74 explanation => EXPL,
75 policy => __PACKAGE__,
76 };
77 0 last;
78 }
79 }
80 elsif ($token_type == LEFT_BRACE) {
81 0 $left_brace_num++;
82 }
83 elsif ($token_type == RIGHT_BRACE) {
84 0 ▶ last if --$left_brace_num <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if --$left_brace_num <= 0 0 0 0
85 }
86 }
87 }
88 }
89  
90 0 return \@violations;
91 }
92  
93 2 1;
94  
« Perl/Lint/Policy/CodeLayout/ProhibitQuotedWordLists.pm ↑ Summary Perl/Lint/Policy/Variables/ProhibitReusedNames.pm »