« 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
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | if ($tokens->[$i]->{kind} == DECL) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/6
$var_type == 166 or $var_type == 191 or $var_type == 194
$var_type == 166 or $var_type == 191
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
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | for ($i++; $i < $token_num; $i++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | my $token = $tokens->[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
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"}}
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"}}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | return \@violations; | |||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||