Perl/Lint/Policy/ControlStructures/ProhibitDeepNests.pm

filter: Statementstmt 32.0% 16 / 50 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 14 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 1 totaltotal 20.0% 21 / 105 CC 20 SCAR 58.2
CC
20
Cov
17%
evaluate
420.0
BEGIN
1.0
BEGIN
1.0
CRAP 336.2
« Perl/Lint/Policy/RegularExpressions/RequireLineBoundaryMatching.pm ↑ Summary Perl/Lint/Policy/BuiltinFunctions/ProhibitVoidMap.pm »
1 package Perl::Lint::Policy::ControlStructures::ProhibitDeepNests;
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 => 'Code structure is deeply nested',
9 EXPL => 'Consider refactoring',
10 2 };
11  
12 0 ▶sub evaluate {
Subroutine evaluate: not called CC=20 SCAR=60.4
Pod undocumented
13 0 my ($class, $file, $tokens, $src, $args) = @_;
14  
15 0 ▶ my $max_nexts = $args->{prohibit_deep_nests}->{max_nests} || 5;
Condition0%0/2
$args->{'prohibit_deep_nests'}{'max_nests'} || 5
l!l
00
MC/DC0%0/1
$args->{'prohibit_deep_nests'}{'max_nests'} || 5
$args->{'prohibit_deep_nests'}{'max_nests'}
Truth table0%0/2
A
A= $args->{'prohibit_deep_nests'}{'max_nests'}
Aresult
11
00
16  
17 0 my @violations;
18 0 my $lbnum = 0;
19 0 my $parent_of_nests_line_number = 0;
20 0 ▶ for (my $i = 0, my $token_type, my $token_data; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
21 0 $token_type = $token->{type};
22 0 $token_data = $token->{data};
23  
24 0 ▶ if ($token_type == LEFT_BRACE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 109) 0 0 0
25 0 ▶ if ($lbnum == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lbnum == 0) 0 0 0
26 0 $parent_of_nests_line_number = $token->{line};
27 }
28  
29 0 $lbnum++;
30  
31 0 ▶ if ($lbnum > $max_nexts) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lbnum > $max_nexts) 0 0 0
32 0 push @violations, {
33 filename => $file,
34 line => $parent_of_nests_line_number,
35 description => DESC,
36 explanation => EXPL,
37 policy => __PACKAGE__,
38 };
39 }
40  
41 0 next;
42 }
43  
44 0 ▶ if ($token_type == RIGHT_BRACE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 110) 0 0 0
45 0 $lbnum--;
46 0 next;
47 }
48  
49 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 166 or $token_type == 194 or $token_type == 63 or $token_type == 70 and $token_data eq "eval") 0 0 0
Condition0%0/12
$token_type == 166 or $token_type == 194 or $token_type == 63 or $token_type == 70 and $token_data eq "eval"
l!l&&r!l&&!r
000
$token_type == 166 or $token_type == 194 or $token_type == 63
l!l&&r!l&&!r
000
$token_type == 166 or $token_type == 194
l!l&&r!l&&!r
000
$token_type == 70 and $token_data eq "eval"
!ll&&!rl&&r
000
MC/DC0%0/5
$token_type == 166 or $token_type == 194 or $token_type == 63 or $token_type == 70 and $token_data eq "eval"
$token_type == 166 $token_type == 194 $token_type == 63 $token_type == 70 $token_data eq "eval"
Truth table0%0/6
A or B or C or D and E
A= $token_type == 166B= $token_type == 194C= $token_type == 63D= $token_type == 70E= $token_data eq "eval"
ABCDEresult
1XXXX1
01XXX1
001XX1
000111
0000X0
000100
50 $token_type == VAR ||
51 $token_type == GLOBAL_VAR ||
52 $token_type == FUNCTION_DECL ||
53 ($token_type == BUILTIN_FUNC && $token_data eq 'eval')
54 ) {
55 0 $token = $tokens->[++$i];
56  
57 0 ▶ if (!$token) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($token) 0 0 0
58 0 last;
59 }
60  
61 0 ▶ if ($token->{type} == POINTER) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->{"type"} == 125) 0 0 0
62 0 $token = $tokens->[++$i];
63 0 ▶ last if !$token;
Branch: 1 branch
BranchTrueFalseTotal
unless $token 0 0 0
64 }
65  
66 0 ▶ if ($token->{type} == LEFT_BRACE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->{"type"} == 109) 0 0 0
67 0 my $unnecessary_lbnum = 1;
68  
69 0 ▶ for ($i++; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
70 0 $token_type = $token->{type};
71  
72 0 ▶ if ($token_type == LEFT_BRACE) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 109) { } 0 0 0
elsif ($token_type == 110) { } 0 0 0
73 0 $unnecessary_lbnum++;
74 }
75 elsif ($token_type == RIGHT_BRACE) {
76 0 ▶ last if --$unnecessary_lbnum <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if --$unnecessary_lbnum <= 0 0 0 0
77 }
78 }
79 }
80  
81 0 next;
82 }
83 }
84  
85 0 return \@violations;
86 }
87  
88 2 1;
89  
« Perl/Lint/Policy/RegularExpressions/RequireLineBoundaryMatching.pm ↑ Summary Perl/Lint/Policy/BuiltinFunctions/ProhibitVoidMap.pm »