Policy/Variables/ProhibitTopicIterator.pm

filter: Statementstmt 85.9% 67 / 78 Branchbran 72.7% 32 / 44 Conditioncond 44.4% 4 / 9 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 100% 13 / 13 Podpod 80.0% 4 / 5 totaltotal 78.0% 121 / 155 CC 26 SCAR 24.1
CC
26
Cov
79%
violates
20.7
__ANON__
7.0
__ANON__
6.4
CRAP 11.1
« Policy/References/ProhibitUnnecessaryRefs.pm ↑ Summary Policy/Subroutines/RequireSubOrder.pm »
1 package Perl::Critic::Policy::Variables::ProhibitTopicIterator;
2  
3 11 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 11 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 11 ▶use Perl::Critic::Utils qw/:severities :classification/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 11 ▶use base 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 11 our $VERSION = '0.1.4';
12  
13 11 Readonly::Scalar my $DESC => q{Always use named loop control variables};
14 11 Readonly::Scalar my $EXPL => undef; # [ ];
15  
16 #-----------------------------------------------------------------------------
17  
18 28 ▶sub applies_to { return 'PPI::Statement::Compound' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
19 8 ▶sub default_severity { return $SEVERITY_LOW }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
20 2 ▶sub default_themes { return qw/maintenance complexity/ }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
21 2 ▶sub supported_parameters { return }
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
22  
23 #-----------------------------------------------------------------------------
24  
25 24 ▶sub violates {
Subroutine violates: called CC=16 SCAR=30.3
Pod documented
26 24 my ($self,$elem,undef)=@_;
27 0 ▶ if(!$elem->isa('PPI::Statement::Compound')) { return }
Branch: 1 branch
BranchTrueFalseTotal
unless ($elem->isa("PPI::Statement::Compound")) 0 24 24
28 24 my $node=$elem->first_element();
29 0 ▶ if(!$node->isa('PPI::Token::Word')) { return }
Branch: 1 branch
BranchTrueFalseTotal
unless ($node->isa("PPI::Token::Word")) 0 24 24
30 24 my $type=$node->content();
31 24 my $next=$node->snext_sibling();
32 0 ▶ if(!$next) { return } # invalid syntax?
Branch: 1 branch
BranchTrueFalseTotal
unless ($next) 0 24 24
33 #
34 24 ▶ if($type=~/^for(?:each)?$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type =~ /^for(?:each)?$/) { } 18 6 24
elsif ($type =~ /^(?:if|while)$/ and $next->isa('PPI::Structure::Condition')) { } 6 0 6
35 18 ▶ if($next->isa('PPI::Structure::List')) { return $self->violation($DESC,$EXPL,$elem) }
Branch: 1 branch
BranchTrueFalseTotal
if ($next->isa("PPI::Structure::List")) 2 16 18
36 16 ▶ if($next->isa('PPI::Token::Magic')&&($next->content() eq '$_')) { return $self->violation($DESC,$EXPL,$elem) }
Branch: 1 branch
BranchTrueFalseTotal
if ($next->isa("PPI::Token::Magic") and $next->content eq "\$_") 2 14 16
Condition66%2/3
$next->isa("PPI::Token::Magic") and $next->content eq "\$_"
!ll&&!rl&&r
1402
MC/DC50%1/2
$next->isa("PPI::Token::Magic") and $next->content eq "\$_"
$next->isa("PPI::Token::Magic") $next->content eq "\$_"
Truth table66%2/3
A and B
A= $next->isa("PPI::Token::Magic")B= $next->content eq "\$_"
ABresult
0X0
100
111
37 14 ▶ if($next->isa('PPI::Structure::For')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next->isa("PPI::Structure::For")) 6 8 14
38 6 ▶ if($next->find_first(sub {
Subroutine __ANON__: called CC=6 SCAR=19.5
Branch: 1 branch
BranchTrueFalseTotal
if ($next->find_first(sub { my(undef, $e) = @_; unless ($e->isa("PPI::Token::Magic")) { return 0; } ; if ($e->content ne "\$_") { return 0; } ; my $ne = $e->snext_sibling; unless ($ne) { return 0; } ; unless ($ne->isa("PPI::Token::Operator")) { return 0; } ; if ($ne->content ne "=") { return 0; } ; return 1; } )) 2 4 6
39 36 my (undef,$e)=@_;
40 36 ▶ if(!$e->isa('PPI::Token::Magic')) { return 0 }
Branch: 1 branch
BranchTrueFalseTotal
unless ($e->isa("PPI::Token::Magic")) 34 2 36
41 0 ▶ if($e->content() ne '$_') { return 0 }
Branch: 1 branch
BranchTrueFalseTotal
if ($e->content ne "\$_") 0 2 2
42 2 my $ne=$e->snext_sibling();
43 0 ▶ if(!$ne) { return 0 }
Branch: 1 branch
BranchTrueFalseTotal
unless ($ne) 0 2 2
44 0 ▶ if(!$ne->isa('PPI::Token::Operator')) { return 0 }
Branch: 1 branch
BranchTrueFalseTotal
unless ($ne->isa("PPI::Token::Operator")) 0 2 2
45 0 ▶ if($ne->content() ne '=') { return 0 }
Branch: 1 branch
BranchTrueFalseTotal
if ($ne->content ne "=") 0 2 2
46 2 return 1;
47 2 })) { return $self->violation($DESC,$EXPL,$elem) }
48 4 return;
49 }
50 8 ▶ if($next->isa('PPI::Token::Symbol')) { return }
Branch: 1 branch
BranchTrueFalseTotal
if ($next->isa("PPI::Token::Symbol")) 4 4 8
51 4 ▶ if($next->isa('PPI::Token::Word')&&($next->content() eq 'my')) { return }
Branch: 1 branch
BranchTrueFalseTotal
if ($next->isa("PPI::Token::Word") and $next->content eq "my") 4 0 4
Condition33%1/3
$next->isa("PPI::Token::Word") and $next->content eq "my"
!ll&&!rl&&r
004
MC/DC0%0/2
$next->isa("PPI::Token::Word") and $next->content eq "my"
$next->isa("PPI::Token::Word") $next->content eq "my"
Truth table33%1/3
A and B
A= $next->isa("PPI::Token::Word")B= $next->content eq "my"
ABresult
0X0
100
111
52 }
53 ▶ elsif(($type=~/^(?:if|while)$/)&&$next->isa('PPI::Structure::Condition')) {
Condition33%1/3
$type =~ /^(?:if|while)$/ and $next->isa("PPI::Structure::Condition")
!ll&&!rl&&r
006
MC/DC0%0/2
$type =~ /^(?:if|while)$/ and $next->isa("PPI::Structure::Condition")
$type =~ /^(?:if|while)$/ $next->isa("PPI::Structure::Condition")
Truth table33%1/3
A and B
A= $type =~ /^(?:if|while)$/B= $next->isa("PPI::Structure::Condition")
ABresult
0X0
100
111
54 6 ▶ if($next->find_first(sub {
Subroutine __ANON__: called CC=6 SCAR=18.6
Branch: 1 branch
BranchTrueFalseTotal
if ($next->find_first(sub { my(undef, $e) = @_; unless ($e->isa("PPI::Token::Magic")) { return 0; } ; if ($e->content ne "\$_") { return 0; } ; my $ne = $e->snext_sibling; unless ($ne) { return 0; } ; unless ($ne->isa("PPI::Token::Operator")) { return 0; } ; if ($ne->content ne "=") { return 0; } ; return 1; } )) 2 4 6
55 32 my (undef,$e)=@_;
56 32 ▶ if(!$e->isa('PPI::Token::Magic')) { return 0 }
Branch: 1 branch
BranchTrueFalseTotal
unless ($e->isa("PPI::Token::Magic")) 29 3 32
57 0 ▶ if($e->content() ne '$_') { return 0 }
Branch: 1 branch
BranchTrueFalseTotal
if ($e->content ne "\$_") 0 3 3
58 3 my $ne=$e->snext_sibling();
59 0 ▶ if(!$ne) { return 0 }
Branch: 1 branch
BranchTrueFalseTotal
unless ($ne) 0 3 3
60 0 ▶ if(!$ne->isa('PPI::Token::Operator')) { return 0 }
Branch: 1 branch
BranchTrueFalseTotal
unless ($ne->isa("PPI::Token::Operator")) 0 3 3
61 3 ▶ if($ne->content() ne '=') { return 0 }
Branch: 1 branch
BranchTrueFalseTotal
if ($ne->content ne "=") 1 2 3
62 2 return 1;
63 2 })) { return $self->violation($DESC,$EXPL,$elem) }
64 4 return;
65 }
66 0 return;
67 }
68  
69 #-----------------------------------------------------------------------------
70  
71 11 1;
72  
73 __END__
« Policy/References/ProhibitUnnecessaryRefs.pm ↑ Summary Policy/Subroutines/RequireSubOrder.pm »