« 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
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'}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 23 | 0 | my $token_type = $token->{type}; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 0 | ▶ | if ($token_type == IF_STATEMENT || $token_type == UNLESS_STATEMENT) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$token_type == 96 or $token_type == 99
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 31 | 0 | $cascading_num++; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | if ($is_chained && $cascading_num > $max_elsif) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$is_chained and $cascading_num > $max_elsif
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 45 | 0 | my $token_type = $token->{type}; | |||||||||||||||||||||||||||
| 46 | 0 | ▶ | if ($token_type == LEFT_BRACE) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 47 | 0 | $left_brace_num++; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | elsif ($token_type == RIGHT_BRACE) { | ||||||||||||||||||||||||||||
| 50 | 0 | ▶ | last if --$left_brace_num <= 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||||