lib/Perl/Critic/Policy/Variables/RequireInitializationForLocalVars.pm

filter: Statementstmt 84.8% 28 / 33 Branchbran 16.6% 1 / 6 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 84.6% 11 / 13 Podpod 80.0% 4 / 5 totaltotal 72.5% 45 / 62 CC 5 SCAR 9.8
CC
5
Cov
71%
_is_initialized
6.0
__ANON__
6.0
violates
3.8
CRAP 2.7
« lib/Perl/Critic/Theme.pm ↑ Summary lib/Perl/Critic/Policy/Miscellanea/ProhibitUselessNoCritic.pm »
1 package Perl::Critic::Policy::Variables::RequireInitializationForLocalVars;
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 40 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 40 ▶use Perl::Critic::Utils qw{ :severities };
Subroutine BEGIN: called CC=1 SCAR=0.0
9 40 ▶use parent 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 40 our $VERSION = '1.156';
12  
13 #-----------------------------------------------------------------------------
14  
15 40 Readonly::Scalar my $DESC => q{"local" variable not initialized};
16 40 Readonly::Scalar my $EXPL => [ 78 ];
17  
18 #-----------------------------------------------------------------------------
19  
20 90 ▶sub supported_parameters { return () }
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
21 74 ▶sub default_severity { return $SEVERITY_MEDIUM }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
22 91 ▶sub default_themes { return qw(core pbp bugs certrec ) }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
23 31 ▶sub applies_to { return 'PPI::Statement::Variable' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
24  
25 #-----------------------------------------------------------------------------
26  
27 85 ▶sub violates {
Subroutine violates: called CC=3 SCAR=13.3
Pod documented
28 85 my ( $self, $elem, undef ) = @_;
29 85 ▶ if ( $elem->type() eq 'local' && !_is_initialized($elem) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->type eq "local" and not _is_initialized($elem)) 0 85 85
Condition33%1/3
$elem->type eq "local" and not _is_initialized($elem)
!ll&&!rl&&r
8500
MC/DC0%0/2
$elem->type eq "local" and not _is_initialized($elem)
$elem->type eq "local" not _is_initialized($elem)
Truth table33%1/3
A and not(B)
A= $elem->type eq "local"B= not _is_initialized($elem)
ABresult
0X0
100
111
30 0 return $self->violation( $DESC, $EXPL, $elem );
31 }
32 85 return; #ok!
33 }
34  
35 #-----------------------------------------------------------------------------
36  
37 0 ▶sub _is_initialized {
Subroutine _is_initialized: not called CC=2 SCAR=17.9
38 0 my $elem = shift;
39 0 ▶ my $wanted = sub { $_[1]->isa('PPI::Token::Operator') && $_[1] eq q{=} };
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_[1]->isa("PPI::Token::Operator") and $_[1] eq "=" 0 0 0
40 0 ▶ return $elem->find( $wanted ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$elem->find($wanted) ? : 0 0 0
41 }
42  
43 40 1;
44  
45 __END__
« lib/Perl/Critic/Theme.pm ↑ Summary lib/Perl/Critic/Policy/Miscellanea/ProhibitUselessNoCritic.pm »