Perl/Lint/Policy/Subroutines/ProhibitExcessComplexity.pm

filter: Statementstmt 43.2% 16 / 37 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 53 MC/DCmcdc 0.0% 0 / 19 Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 1 totaltotal 15.9% 21 / 132 CC 27 SCAR 64.6
CC
27
Cov
15%
evaluate
756.0
BEGIN
1.0
BEGIN
1.0
CRAP 638.0
« Perl/Lint/Policy/Variables/ProhibitUnusedVariables.pm ↑ Summary Perl/Lint/Policy/Modules/ProhibitExcessMainComplexity.pm »
1 package Perl::Lint::Policy::Subroutines::ProhibitExcessComplexity;
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 => 'The maximum complexity score allowed',
9 EXPL => 'Consider refactoring',
10 2 };
11  
12 0 ▶sub evaluate {
Subroutine evaluate: not called CC=27 SCAR=66.3
Pod undocumented
13 0 my ($class, $file, $tokens, $src, $args) = @_;
14  
15 0 ▶ my $max_mccabe = $args->{prohibit_excess_complexity}->{max_mccabe} || 20;
Condition0%0/2
$args->{'prohibit_excess_complexity'}{'max_mccabe'} || 20
l!l
00
MC/DC0%0/1
$args->{'prohibit_excess_complexity'}{'max_mccabe'} || 20
$args->{'prohibit_excess_complexity'}{'max_mccabe'}
Truth table0%0/2
A
A= $args->{'prohibit_excess_complexity'}{'max_mccabe'}
Aresult
11
00
16  
17 0 my @violations;
18 0 ▶ for (my $i = 0; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
19 0 my $token_type = $token->{type};
20  
21 0 my $left_brace_num = 0;
22 0 ▶ if ($token_type == FUNCTION_DECL) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 63) 0 0 0
23 0 my $mccabe = 0;
24 0 my $function_decl_token = $token;
25 0 ▶ for ($i++; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
26 0 $token_type = $token->{type};
27  
28 0 my $next_token = $tokens->[$i+1];
29 0 my $next_token_type = $next_token->{type};
30  
31 0 ▶ if ($token_type == LEFT_BRACE) {
Branch: 3 branches
BranchTrueFalseTotal
if ($token_type == 109) { } 0 0 0
elsif ($token_type == 110) { } 0 0 0
elsif ($token_type == 52 or $token_type == 53 or $token_type == 16 or $token_type == 14 or $token_type == 18 or $token_type == 57 or $token_type == 58 or $token_type == 6 or $token_type == 96 or $token_type == 98 or $token_type == 97 or $token_type == 99 or $token_type == 132 or $token_type == 100 or $token_type == 133 or $token_type == 134 or $token_type == 26 or $token_type == 27) { } 0 0 0
32 0 $left_brace_num++;
33 }
34 elsif ($token_type == RIGHT_BRACE) {
35 0 ▶ if (--$left_brace_num < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (--$left_brace_num < 0) 0 0 0
36 0 last;
37 }
38 }
39 ▶ elsif (
Condition0%0/51
$token_type == 52 or $token_type == 53 or $token_type == 16 or $token_type == 14 or $token_type == 18 or $token_type == 57 or $token_type == 58 or $token_type == 6 or $token_type == 96 or $token_type == 98 or $token_type == 97 or $token_type == 99 or $token_type == 132 or $token_type == 100 or $token_type == 133 or $token_type == 134 or $token_type == 26 or $token_type == 27
l!l&&r!l&&!r
000
$token_type == 52 or $token_type == 53 or $token_type == 16 or $token_type == 14 or $token_type == 18 or $token_type == 57 or $token_type == 58 or $token_type == 6 or $token_type == 96 or $token_type == 98 or $token_type == 97 or $token_type == 99 or $token_type == 132 or $token_type == 100 or $token_type == 133 or $token_type == 134 or $token_type == 26
l!l&&r!l&&!r
000
$token_type == 52 or $token_type == 53 or $token_type == 16 or $token_type == 14 or $token_type == 18 or $token_type == 57 or $token_type == 58 or $token_type == 6 or $token_type == 96 or $token_type == 98 or $token_type == 97 or $token_type == 99 or $token_type == 132 or $token_type == 100 or $token_type == 133 or $token_type == 134
l!l&&r!l&&!r
000
$token_type == 52 or $token_type == 53 or $token_type == 16 or $token_type == 14 or $token_type == 18 or $token_type == 57 or $token_type == 58 or $token_type == 6 or $token_type == 96 or $token_type == 98 or $token_type == 97 or $token_type == 99 or $token_type == 132 or $token_type == 100 or $token_type == 133
l!l&&r!l&&!r
000
$token_type == 52 or $token_type == 53 or $token_type == 16 or $token_type == 14 or $token_type == 18 or $token_type == 57 or $token_type == 58 or $token_type == 6 or $token_type == 96 or $token_type == 98 or $token_type == 97 or $token_type == 99 or $token_type == 132 or $token_type == 100
l!l&&r!l&&!r
000
$token_type == 52 or $token_type == 53 or $token_type == 16 or $token_type == 14 or $token_type == 18 or $token_type == 57 or $token_type == 58 or $token_type == 6 or $token_type == 96 or $token_type == 98 or $token_type == 97 or $token_type == 99 or $token_type == 132
l!l&&r!l&&!r
000
$token_type == 52 or $token_type == 53 or $token_type == 16 or $token_type == 14 or $token_type == 18 or $token_type == 57 or $token_type == 58 or $token_type == 6 or $token_type == 96 or $token_type == 98 or $token_type == 97 or $token_type == 99
l!l&&r!l&&!r
000
$token_type == 52 or $token_type == 53 or $token_type == 16 or $token_type == 14 or $token_type == 18 or $token_type == 57 or $token_type == 58 or $token_type == 6 or $token_type == 96 or $token_type == 98 or $token_type == 97
l!l&&r!l&&!r
000
$token_type == 52 or $token_type == 53 or $token_type == 16 or $token_type == 14 or $token_type == 18 or $token_type == 57 or $token_type == 58 or $token_type == 6 or $token_type == 96 or $token_type == 98
l!l&&r!l&&!r
000
$token_type == 52 or $token_type == 53 or $token_type == 16 or $token_type == 14 or $token_type == 18 or $token_type == 57 or $token_type == 58 or $token_type == 6 or $token_type == 96
l!l&&r!l&&!r
000
$token_type == 52 or $token_type == 53 or $token_type == 16 or $token_type == 14 or $token_type == 18 or $token_type == 57 or $token_type == 58 or $token_type == 6
l!l&&r!l&&!r
000
$token_type == 52 or $token_type == 53 or $token_type == 16 or $token_type == 14 or $token_type == 18 or $token_type == 57 or $token_type == 58
l!l&&r!l&&!r
000
$token_type == 52 or $token_type == 53 or $token_type == 16 or $token_type == 14 or $token_type == 18 or $token_type == 57
l!l&&r!l&&!r
000
$token_type == 52 or $token_type == 53 or $token_type == 16 or $token_type == 14 or $token_type == 18
l!l&&r!l&&!r
000
$token_type == 52 or $token_type == 53 or $token_type == 16 or $token_type == 14
l!l&&r!l&&!r
000
$token_type == 52 or $token_type == 53 or $token_type == 16
l!l&&r!l&&!r
000
$token_type == 52 or $token_type == 53
l!l&&r!l&&!r
000
MC/DC0%0/18
$token_type == 52 or $token_type == 53 or $token_type == 16 or $token_type == 14 or $token_type == 18 or $token_type == 57 or $token_type == 58 or $token_type == 6 or $token_type == 96 or $token_type == 98 or $token_type == 97 or $token_type == 99 or $token_type == 132 or $token_type == 100 or $token_type == 133 or $token_type == 134 or $token_type == 26 or $token_type == 27
too many conditions
40 $token_type == AND ||
41 $token_type == OR ||
42 $token_type == ALPHABET_AND ||
43 $token_type == ALPHABET_OR ||
44 $token_type == ALPHABET_XOR ||
45 $token_type == OR_EQUAL ||
46 $token_type == AND_EQUAL ||
47 $token_type == THREE_TERM_OP ||
48 $token_type == IF_STATEMENT ||
49 $token_type == ELSIF_STATEMENT ||
50 $token_type == ELSE_STATEMENT ||
51 $token_type == UNLESS_STATEMENT ||
52 $token_type == WHILE_STATEMENT ||
53 $token_type == UNTIL_STATEMENT ||
54 $token_type == FOR_STATEMENT ||
55 $token_type == FOREACH_STATEMENT ||
56 $token_type == LEFT_SHIFT_EQUAL ||
57 $token_type == RIGHT_SHIFT_EQUAL
58 ) {
59 0 $mccabe++;
60 }
61 }
62  
63 0 ▶ if ($mccabe > $max_mccabe) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mccabe > $max_mccabe) 0 0 0
64 push @violations, {
65 filename => $file,
66 line => $function_decl_token->{line},
67 0 description => DESC,
68 explanation => EXPL,
69 policy => __PACKAGE__,
70 };
71 }
72 }
73 }
74  
75 0 return \@violations;
76 }
77  
78 2 1;
79  
« Perl/Lint/Policy/Variables/ProhibitUnusedVariables.pm ↑ Summary Perl/Lint/Policy/Modules/ProhibitExcessMainComplexity.pm »