lib/Perl/Critic/Policy/BuiltinFunctions/ProhibitShiftRef.pm

filter: Statementstmt 79.0% 34 / 43 Branchbran 10.0% 1 / 10 Conditioncond 8.3% 1 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 100% 13 / 13 Podpod 83.3% 5 / 6 totaltotal 59.3% 54 / 91 CC 10 SCAR 33.5
CC
10
Cov
55%
violates
68.0
prepare_to_scan_document
2.1
BEGIN
1.0
CRAP 28.5
« lib/Perl/Critic/Policy/Variables/ProhibitReusedNames.pm ↑ Summary lib/Perl/Critic/Policy/CodeLayout/ProhibitParensWithBuiltins.pm »
1 package Perl::Critic::Policy::BuiltinFunctions::ProhibitShiftRef;
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 40 ▶use version 0.77 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 40 ▶use Perl::Critic::Utils qw{ :severities :classification :language };
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{\shift used};
17 40 Readonly::Scalar my $EXPL => [165];
18  
19 40 Readonly::Scalar my $MINIMUM_PERL_VERSION => version->new(5.008008);
20  
21 #-----------------------------------------------------------------------------
22  
23 90 ▶sub supported_parameters { return () }
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
24 74 ▶sub default_severity { return $SEVERITY_MEDIUM }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
25 73 ▶sub default_themes { return qw( core bugs tests ) }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
26 31 ▶sub applies_to { return 'PPI::Token::Word' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
27  
28 #-----------------------------------------------------------------------------
29  
30 31 ▶sub prepare_to_scan_document {
Subroutine prepare_to_scan_document: called CC=2 SCAR=7.6
Pod documented
31 31 my ( undef, $document ) = @_;
32  
33 # The earliest version tested was 5.8.8
34 31 my $version = $document->highest_explicit_perl_version();
35 31 ▶ return !$version || $version >= $MINIMUM_PERL_VERSION;
Condition33%1/3
!$version || $version >= $MINIMUM_PERL_VERSION
l!l&&r!l&&!r
3100
MC/DC0%0/2
!$version || $version >= $MINIMUM_PERL_VERSION
!$version $version >= $MINIMUM_PERL_VERSION
Truth table33%1/3
not(A) || B
A= !$versionB= $version >= $MINIMUM_PERL_VERSION
ABresult
1X1
011
000
36 }
37  
38 #-----------------------------------------------------------------------------
39  
40 332 ▶sub violates {
Subroutine violates: called CC=9 SCAR=42.2
Pod documented
41 332 my ( $self, $elem, undef ) = @_;
42  
43 332 ▶ return if $elem->content() ne 'shift';
Branch: 1 branch
BranchTrueFalseTotal
if $elem->content ne "shift" 332 0 332
44  
45 0 my $prev = $elem->sprevious_sibling();
46 0 ▶ if ( !$prev ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($prev) 0 0 0
47  
48 # If there is no previous token, we are probably nested in a block.
49 # Grab the statement and see if it's in a block. For simplicity, we
50 # assume the block only contains a 'shift' statement, which may not be
51 # reliable.
52 0 ▶ if ( my $stmt = $elem->statement ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $stmt = $elem->statement) 0 0 0
53  
54 0 my $block = $stmt->parent();
55 0 ▶ if ( $block && $block->isa('PPI::Structure::Block') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($block and $block->isa("PPI::Structure::Block")) 0 0 0
Condition0%0/3
$block and $block->isa("PPI::Structure::Block")
!ll&&!rl&&r
000
MC/DC0%0/2
$block and $block->isa("PPI::Structure::Block")
$block $block->isa("PPI::Structure::Block")
Truth table0%0/3
A and B
A= $blockB= $block->isa("PPI::Structure::Block")
ABresult
0X0
100
111
56 0 $prev = $block->sprevious_sibling();
57 }
58 }
59 }
60  
61 0 ▶ if ( $prev && $prev->isa('PPI::Token::Cast') && $prev->content() eq q{\\} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prev and $prev->isa("PPI::Token::Cast") and $prev->content eq "\\") 0 0 0
Condition0%0/6
$prev and $prev->isa("PPI::Token::Cast") and $prev->content eq "\\"
!ll&&!rl&&r
000
$prev and $prev->isa("PPI::Token::Cast")
!ll&&!rl&&r
000
MC/DC0%0/3
$prev and $prev->isa("PPI::Token::Cast") and $prev->content eq "\\"
$prev $prev->isa("PPI::Token::Cast") $prev->content eq "\\"
Truth table0%0/4
A and B and C
A= $prevB= $prev->isa("PPI::Token::Cast")C= $prev->content eq "\\"
ABCresult
0XX0
10X0
1100
1111
62 0 return $self->violation( $DESC, $EXPL, $elem );
63 }
64  
65 0 return;
66 }
67  
68 40 1;
69  
70 #-----------------------------------------------------------------------------
71  
72 __END__
« lib/Perl/Critic/Policy/Variables/ProhibitReusedNames.pm ↑ Summary lib/Perl/Critic/Policy/CodeLayout/ProhibitParensWithBuiltins.pm »