line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Lint::Policy::Subroutines::ProhibitExcessComplexity; |
2
|
133
|
|
|
133
|
|
68248
|
use strict; |
|
133
|
|
|
|
|
202
|
|
|
133
|
|
|
|
|
3211
|
|
3
|
133
|
|
|
133
|
|
484
|
use warnings; |
|
133
|
|
|
|
|
174
|
|
|
133
|
|
|
|
|
2486
|
|
4
|
133
|
|
|
133
|
|
813
|
use Perl::Lint::Constants::Type; |
|
133
|
|
|
|
|
167
|
|
|
133
|
|
|
|
|
60730
|
|
5
|
133
|
|
|
133
|
|
605
|
use parent "Perl::Lint::Policy"; |
|
133
|
|
|
|
|
197
|
|
|
133
|
|
|
|
|
588
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use constant { |
8
|
133
|
|
|
|
|
36281
|
DESC => 'The maximum complexity score allowed', |
9
|
|
|
|
|
|
|
EXPL => 'Consider refactoring', |
10
|
133
|
|
|
133
|
|
6714
|
}; |
|
133
|
|
|
|
|
198
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub evaluate { |
13
|
5
|
|
|
5
|
0
|
10
|
my ($class, $file, $tokens, $src, $args) = @_; |
14
|
|
|
|
|
|
|
|
15
|
5
|
|
100
|
|
|
18
|
my $max_mccabe = $args->{prohibit_excess_complexity}->{max_mccabe} || 20; |
16
|
|
|
|
|
|
|
|
17
|
5
|
|
|
|
|
7
|
my @violations; |
18
|
5
|
|
|
|
|
17
|
for (my $i = 0; my $token = $tokens->[$i]; $i++) { |
19
|
5
|
|
|
|
|
7
|
my $token_type = $token->{type}; |
20
|
|
|
|
|
|
|
|
21
|
5
|
|
|
|
|
5
|
my $left_brace_num = 0; |
22
|
5
|
50
|
|
|
|
9
|
if ($token_type == FUNCTION_DECL) { |
23
|
5
|
|
|
|
|
7
|
my $mccabe = 0; |
24
|
5
|
|
|
|
|
4
|
my $function_decl_token = $token; |
25
|
5
|
|
|
|
|
12
|
for ($i++; $token = $tokens->[$i]; $i++) { |
26
|
282
|
|
|
|
|
172
|
$token_type = $token->{type}; |
27
|
|
|
|
|
|
|
|
28
|
282
|
|
|
|
|
202
|
my $next_token = $tokens->[$i+1]; |
29
|
282
|
|
|
|
|
194
|
my $next_token_type = $next_token->{type}; |
30
|
|
|
|
|
|
|
|
31
|
282
|
100
|
100
|
|
|
4633
|
if ($token_type == LEFT_BRACE) { |
|
|
100
|
100
|
|
|
|
|
|
|
100
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
32
|
25
|
|
|
|
|
34
|
$left_brace_num++; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
elsif ($token_type == RIGHT_BRACE) { |
35
|
25
|
50
|
|
|
|
52
|
if (--$left_brace_num < 0) { |
36
|
0
|
|
|
|
|
0
|
last; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
elsif ( |
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
|
53
|
|
|
|
|
67
|
$mccabe++; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
5
|
100
|
|
|
|
13
|
if ($mccabe > $max_mccabe) { |
64
|
|
|
|
|
|
|
push @violations, { |
65
|
|
|
|
|
|
|
filename => $file, |
66
|
|
|
|
|
|
|
line => $function_decl_token->{line}, |
67
|
3
|
|
|
|
|
22
|
description => DESC, |
68
|
|
|
|
|
|
|
explanation => EXPL, |
69
|
|
|
|
|
|
|
policy => __PACKAGE__, |
70
|
|
|
|
|
|
|
}; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
5
|
|
|
|
|
18
|
return \@violations; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
|