Perl/Lint/Policy/ControlStructures/ProhibitCascadingIfElse.pm

filter: Statementstmt 42.2% 19 / 45 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 85.7% 6 / 7 Podpod 0.0% 0 / 1 totaltotal 30.4% 25 / 82 CC 12 SCAR 46.5
CC
12
Cov
28%
evaluate
156.0
BEGIN
1.0
BEGIN
1.0
CRAP 104.3
« Perl/Lint/Policy/Modules/RequireExplicitPackage.pm ↑ Summary Perl/Lint/Policy/CodeLayout/RequireTrailingCommas.pm »
1 package Perl::Lint::Policy::ControlStructures::ProhibitCascadingIfElse;
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 Perl::Lint::Constants::Kind;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use parent "Perl::Lint::Policy";
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 DESC => 'Cascading if-elsif chain',
10 EXPL => [117, 118],
11 2 };
12  
13 0 ▶sub evaluate {
Subroutine evaluate: not called CC=12 SCAR=50.5
Pod undocumented
14 0 my ($class, $file, $tokens, $src, $args) = @_;
15  
16 0 ▶ my $max_elsif = $args->{prohibit_cascading_if_else}->{max_elsif} || 2;
Condition0%0/2
$args->{'prohibit_cascading_if_else'}{'max_elsif'} || 2
l!l
00
MC/DC0%0/1
$args->{'prohibit_cascading_if_else'}{'max_elsif'} || 2
$args->{'prohibit_cascading_if_else'}{'max_elsif'}
Truth table0%0/2
A
A= $args->{'prohibit_cascading_if_else'}{'max_elsif'}
Aresult
11
00
17  
18 0 my @violations;
19 0 my $is_chained = 0;
20 0 my $cascading_num = 0;
21 0 my $top_of_conditional_branch_line_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  
25 0 ▶ if ($token_type == IF_STATEMENT || $token_type == UNLESS_STATEMENT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 96 or $token_type == 99) 0 0 0
Condition0%0/3
$token_type == 96 or $token_type == 99
l!l&&r!l&&!r
000
MC/DC0%0/2
$token_type == 96 or $token_type == 99
$token_type == 96 $token_type == 99
Truth table0%0/3
A or B
A= $token_type == 96B= $token_type == 99
ABresult
1X1
011
000
26 0 $top_of_conditional_branch_line_num = $token->{line};
27 0 next;
28 }
29  
30 0 ▶ if ($token_type == ELSIF_STATEMENT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 98) 0 0 0
31 0 $cascading_num++;
32  
33 0 ▶ if ($is_chained && $cascading_num > $max_elsif) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_chained and $cascading_num > $max_elsif) 0 0 0
Condition0%0/3
$is_chained and $cascading_num > $max_elsif
!ll&&!rl&&r
000
MC/DC0%0/2
$is_chained and $cascading_num > $max_elsif
$is_chained $cascading_num > $max_elsif
Truth table0%0/3
A and B
A= $is_chainedB= $cascading_num > $max_elsif
ABresult
0X0
100
111
34 0 push @violations, {
35 filename => $file,
36 line => $top_of_conditional_branch_line_num,
37 description => DESC,
38 explanation => EXPL,
39 policy => __PACKAGE__,
40 };
41 }
42  
43 0 my $left_brace_num = 0;
44 0 ▶ for ($i++; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
45 0 my $token_type = $token->{type};
46 0 ▶ if ($token_type == LEFT_BRACE) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 109) { } 0 0 0
elsif ($token_type == 110) { } 0 0 0
47 0 $left_brace_num++;
48 }
49 elsif ($token_type == RIGHT_BRACE) {
50 0 ▶ last if --$left_brace_num <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if --$left_brace_num <= 0 0 0 0
51 }
52 }
53 0 $is_chained = 1;
54 0 next;
55 }
56  
57 0 $cascading_num = 0;
58 0 $is_chained = 0;
59 }
60  
61 0 return \@violations;
62 }
63  
64 2 1;
65  
66  
« Perl/Lint/Policy/Modules/RequireExplicitPackage.pm ↑ Summary Perl/Lint/Policy/CodeLayout/RequireTrailingCommas.pm »