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

filter: Statementstmt 97.3% 37 / 38 Branchbran 50.0% 3 / 6 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 13 / 13 Podpod 80.0% 4 / 5 totaltotal 86.5% 58 / 67 CC 5 SCAR 8.8
CC
5
Cov
87%
violates
5.8
BEGIN
1.0
BEGIN
1.0
CRAP 2.4
« lib/Perl/Critic/PolicyParameter/Behavior/StringList.pm ↑ Summary lib/Perl/Critic/Policy/ValuesAndExpressions/ProhibitVersionStrings.pm »
1 package Perl::Critic::Policy::Variables::ProhibitAugmentedAssignmentInDeclaration;
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 List::SomeUtils qw( firstval );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 40 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 40 ▶use Perl::Critic::Utils qw{ :severities :data_conversion };
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{Augmented assignment operator '%s' used in declaration};
17 40 Readonly::Scalar my $EXPL => q{Use simple assignment when initializing variables};
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 => 'allow_our',
25 description =>
26 q<Allow augmented assignment for our variables.>,
27 default_string => '0',
28 behavior => 'boolean',
29 },
30 );
31 }
32 74 ▶sub default_severity { return $SEVERITY_HIGH }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
33 73 ▶sub default_themes { return qw( core bugs ) }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
34 33 ▶sub applies_to { return 'PPI::Statement::Variable' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
35  
36 #-----------------------------------------------------------------------------
37  
38 90 ▶sub violates {
Subroutine violates: called CC=5 SCAR=17.6
Pod documented
39 90 my ( $self, $elem, undef ) = @_;
40  
41 90 state $augmented_assignments = { hashify( qw( **= += -= .= *= /= %= x= &= |= ^= <<= >>= &&= ||= //= ) ) };
42  
43 # The assignment operator associated with a PPI::Statement::Variable
44 # element is assumed to be the first immediate child of that element.
45 # Other operators in the statement, e.g. the ',' in "my ( $a, $b ) = ();",
46 # as assumed to never be immediate children.
47 #
48 return
49 90 ▶ if $self->{_allow_our} and $elem->type eq 'our';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_allow_our"} and $elem->type eq "our" 0 90 90
Condition33%1/3
$self->{"_allow_our"} and $elem->type eq "our"
!ll&&!rl&&r
9000
MC/DC0%0/2
$self->{"_allow_our"} and $elem->type eq "our"
$self->{"_allow_our"} $elem->type eq "our"
Truth table33%1/3
A and B
A= $self->{"_allow_our"}B= $elem->type eq "our"
ABresult
0X0
100
111
50  
51 90 ▶ my $found = firstval { $_->isa('PPI::Token::Operator') } $elem->children();
Subroutine __ANON__: called CC=1 SCAR=0.0
52 90 ▶ if ( $found ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($found) 90 0 90
53 90 my $op = $found->content();
54 90 ▶ if ( exists $augmented_assignments->{ $op } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $augmented_assignments->{$op}) 0 90 90
55 0 return $self->violation( sprintf( $DESC, $op ), $EXPL, $found );
56 }
57 }
58  
59 90 return;
60 }
61  
62  
63 40 1;
64  
65 __END__
« lib/Perl/Critic/PolicyParameter/Behavior/StringList.pm ↑ Summary lib/Perl/Critic/Policy/ValuesAndExpressions/ProhibitVersionStrings.pm »