lib/Perl/Critic/Policy/ControlStructures/ProhibitCascadingIfElse.pm

filter: Statementstmt 96.9% 32 / 33 Branchbran 75.0% 3 / 4 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 12 / 12 Podpod 80.0% 4 / 5 totaltotal 89.8% 53 / 59 CC 4 SCAR 4.4
CC
4
Cov
92%
violates
3.1
_count_elsifs
2.0
BEGIN
1.0
CRAP 1.6
« lib/Perl/Critic/Policy/RegularExpressions/RequireLineBoundaryMatching.pm ↑ Summary lib/Perl/Critic/Policy/ValuesAndExpressions/ProhibitConstantPragma.pm »
1 package Perl::Critic::Policy::ControlStructures::ProhibitCascadingIfElse;
2  
3 40 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 40 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 40 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 40 ▶use Perl::Critic::Utils qw{ :severities };
Subroutine BEGIN: called CC=1 SCAR=0.0
10 40 ▶use parent 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 40 our $VERSION = '1.156';
13  
14 #-----------------------------------------------------------------------------
15  
16 40 Readonly::Scalar my $DESC => q{Cascading if-elsif chain};
17 40 Readonly::Scalar my $EXPL => [ 117, 118 ];
18  
19 #-----------------------------------------------------------------------------
20  
21 91 ▶sub supported_parameters {
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
22 return (
23 {
24 91 name => 'max_elsif',
25 description => 'The maximum number of alternatives that will be allowed.',
26 default_string => '2',
27 behavior => 'integer',
28 integer_minimum => 1,
29 },
30 );
31 }
32  
33 74 ▶sub default_severity { return $SEVERITY_MEDIUM }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
34 85 ▶sub default_themes { return qw( core pbp maintenance complexity ) }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
35 31 ▶sub applies_to { return 'PPI::Statement::Compound' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
36  
37 #-----------------------------------------------------------------------------
38  
39 11 ▶sub violates {
Subroutine violates: called CC=3 SCAR=11.3
Pod documented
40 11 my ( $self, $elem, undef ) = @_;
41  
42 11 ▶ return if ($elem->type() ne 'if');
Branch: 1 branch
BranchTrueFalseTotal
if $elem->type ne "if" 9 2 11
43  
44 2 ▶ if ( _count_elsifs($elem) > $self->{_max_elsif} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_count_elsifs($elem) > $self->{"_max_elsif"}) 0 2 2
45 0 return $self->violation( $DESC, $EXPL, $elem );
46 }
47 2 return; #ok!
48 }
49  
50 2 ▶sub _count_elsifs {
Subroutine _count_elsifs: called CC=2 SCAR=7.0
51 2 my $elem = shift;
52 return
53 2 ▶ grep { $_->isa('PPI::Token::Word') && $_->content() eq 'elsif' } $elem->schildren();
Condition66%2/3
$_->isa('PPI::Token::Word') && $_->content eq 'elsif'
!ll&&!rl&&r
420
MC/DC0%0/2
$_->isa('PPI::Token::Word') && $_->content eq 'elsif'
$_->isa('PPI::Token::Word') $_->content eq 'elsif'
Truth table66%2/3
A && B
A= $_->isa('PPI::Token::Word')B= $_->content eq 'elsif'
ABresult
0X0
100
111
54 }
55  
56 40 1;
57  
58 __END__
« lib/Perl/Critic/Policy/RegularExpressions/RequireLineBoundaryMatching.pm ↑ Summary lib/Perl/Critic/Policy/ValuesAndExpressions/ProhibitConstantPragma.pm »