Perl/Lint/Policy/Variables/ProhibitAugmentedAssignmentInDeclaration.pm

filter: Statementstmt 51.6% 16 / 31 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 1 totaltotal 30.4% 21 / 69 CC 11 SCAR 45.1
CC
11
Cov
29%
evaluate
132.0
BEGIN
1.0
BEGIN
1.0
CRAP 91.1
« Perl/Lint/Policy/Modules/RequireBarewordIncludes.pm ↑ Summary Perl/Lint/Policy/Variables/RequireLexicalLoopIterators.pm »
1 package Perl::Lint::Policy::Variables::ProhibitAugmentedAssignmentInDeclaration;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Compiler::Lexer::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use parent "Perl::Lint::Policy";
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 DESC => q{Augmented assignment operator '%s' used in declaration},
9 EXPL => q{Use simple assignment when initializing variables},
10 AUGMENTED_ASSIGNMENTS => {
11 '**=' => 1, '+=' => 1, '-=' => 1, '.=' => 1,
12 '*=' => 1, '/=' => 1, '%=' => 1, 'x=' => 1,
13 '&=' => 1, '|=' => 1, '^=' => 1, '<<=' => 1,
14 '>>=' => 1, '&&=' => 1, '||=' => 1, '//=' => 1,
15 },
16 VAR => Compiler::Lexer::TokenType::T_Var,
17 LOCAL_VAR => Compiler::Lexer::TokenType::T_LocalVar,
18 GLOBAL_VAR => Compiler::Lexer::TokenType::T_GlobalVar,
19 SEMI_COLON => Compiler::Lexer::TokenType::T_SemiColon,
20 ASSIGN => Compiler::Lexer::TokenType::T_Assign,
21 DECL => Compiler::Lexer::Kind::T_Decl,
22 KIND_ASSIGN => Compiler::Lexer::Kind::T_Assign,
23 2 };
24  
25 0 ▶sub evaluate {
Subroutine evaluate: not called CC=11 SCAR=48.8
Pod undocumented
26 0 my ($class, $file, $tokens) = @_;
27  
28 0 my @violations;
29 0 my $token_num = scalar @$tokens;
30 0 ▶ for (my $i = 0; $i < $token_num; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $token_num) 0 0 0
31 0 ▶ if ($tokens->[$i]->{kind} == DECL) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tokens->[$i]{"kind"} == 3) 0 0 0
32 0 $i++;
33 0 my $var_type = $tokens->[$i]->{type};
34 0 ▶ if ($var_type == VAR || $var_type == LOCAL_VAR || $var_type == GLOBAL_VAR) {
Branch: 1 branch
BranchTrueFalseTotal
if ($var_type == 166 or $var_type == 191 or $var_type == 194) 0 0 0
Condition0%0/6
$var_type == 166 or $var_type == 191 or $var_type == 194
l!l&&r!l&&!r
000
$var_type == 166 or $var_type == 191
l!l&&r!l&&!r
000
MC/DC0%0/3
$var_type == 166 or $var_type == 191 or $var_type == 194
$var_type == 166 $var_type == 191 $var_type == 194
Truth table0%0/4
A or B or C
A= $var_type == 166B= $var_type == 191C= $var_type == 194
ABCresult
1XX1
01X1
0011
0000
35 0 ▶ for ($i++; $i < $token_num; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $token_num) 0 0 0
36 0 my $token = $tokens->[$i];
37 0 ▶ if (
Branch: 2 branches
BranchTrueFalseTotal
if ($token->{'kind'} == 2 and {%= => 1, &&= => 1, &= => 1, **= => 1, *= => 1, += => 1, -= => 1, .= => 1, //= => 1, /= => 1, <<= => 1, >>= => 1, ^= => 1, x= => 1, |= => 1, ||= => 1}->{$token->{'data'}}) { } 0 0 0
elsif ($token->{'type'} == 65 or $token->{'type'} == 106) { } 0 0 0
Condition0%0/3
$token->{"kind"} == 2 and {"%=" => 1,"&&=" => 1,"&=" => 1,"**=" => 1,"*=" => 1,"+=" => 1,"-=" => 1,".=" => 1,"//=" => 1,"/=" => 1,"<<=" => 1,">>=" => 1,"^=" => 1,"x=" => 1,"|=" => 1,"||=" => 1}->{$token->{"data"}}
!ll&&!rl&&r
000
MC/DC0%0/2
$token->{"kind"} == 2 and {"%=" => 1,"&&=" => 1,"&=" => 1,"**=" => 1,"*=" => 1,"+=" => 1,"-=" => 1,".=" => 1,"//=" => 1,"/=" => 1,"<<=" => 1,">>=" => 1,"^=" => 1,"x=" => 1,"|=" => 1,"||=" => 1}->{$token->{"data"}}
$token->{"kind"} == 2 {"%=" => 1,"&&=" => 1,"&=" => 1,"**=" => 1,"*=" => 1,"+=" => 1,"-=" => 1,".=" => 1,"//=" => 1,"/=" => 1,"<<=" => 1,">>=" => 1,"^=" => 1,"x=" => 1,"|=" => 1,"||=" => 1}->{$token->{"data"}}
Truth table0%0/3
A and B
A= $token->{"kind"} == 2B= {"%=" => 1,"&&=" => 1,"&=" => 1,"**=" => 1,"*=" => 1,"+=" => 1,"-=" => 1,".=" => 1,"//=" => 1,"/=" => 1,"<<=" => 1,">>=" => 1,"^=" => 1,"x=" => 1,"|=" => 1,"||=" => 1}->{$token->{"data"}}
ABresult
0X0
100
111
38 $token->{kind} == KIND_ASSIGN &&
39 AUGMENTED_ASSIGNMENTS->{$token->{data}} # XXX Not good
40 ) {
41 push @violations, {
42 filename => $file,
43 line => $token->{line},
44 0 description => sprintf(DESC, $token->{data}),
45 explanation => EXPL,
46 policy => __PACKAGE__,
47 };
48 0 last;
49 }
50 ▶ elsif ($token->{type} == ASSIGN || $token->{type} == SEMI_COLON) {
Condition0%0/3
$token->{"type"} == 65 or $token->{"type"} == 106
l!l&&r!l&&!r
000
MC/DC0%0/2
$token->{"type"} == 65 or $token->{"type"} == 106
$token->{"type"} == 65 $token->{"type"} == 106
Truth table0%0/3
A or B
A= $token->{"type"} == 65B= $token->{"type"} == 106
ABresult
1X1
011
000
51 0 last;
52 }
53 }
54 }
55 }
56 }
57 0 return \@violations;
58 }
59  
60 2 1;
61  
« Perl/Lint/Policy/Modules/RequireBarewordIncludes.pm ↑ Summary Perl/Lint/Policy/Variables/RequireLexicalLoopIterators.pm »