« Perl/Lint/Policy/Modules/ProhibitConditionalUseStatements.pm
↑ Summary
Perl/Lint/Policy/TestingAndDebugging/RequireTestLabels.pm »
| 1 | package Perl::Lint::Policy::ValuesAndExpressions::ProhibitMagicNumbers; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | no warnings qw/numeric/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use Perl::Lint::Constants::Type; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use parent "Perl::Lint::Policy"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use constant { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | DESC => 'Unnamed numeric literals make code less maintainable', # TODO | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | EXPL => 'Unnamed numeric literals make code less maintainable', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 3 | my $file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | my $tokens; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 3 | my %allowed_values; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 3 | my %allowed_types; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 3 | my %constant_creator_subroutines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 3 | my $allow_to_the_right_of_a_fat_comma; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 3 | my $is_readonly_array1_ctx; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | ▶ | sub evaluate { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
evaluate: called CC=74 SCAR=78.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 2 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | $file = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 2 | $tokens = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 2 | my ($src, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 2 | %allowed_values = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 1 => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 2 => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 2 | %allowed_types = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | Int => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | Float => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 2 | %constant_creator_subroutines = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | plan => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | Readonly => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | const => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 2 | $allow_to_the_right_of_a_fat_comma = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # initializing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 2 | ▶ | if (my $this_policies_arg = $args->{prohibit_magic_numbers}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | $allow_to_the_right_of_a_fat_comma = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | $this_policies_arg->{allow_to_the_right_of_a_fat_comma} // 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$this_policies_arg->{"allow_to_the_right_of_a_fat_comma"} // 1
MC/DC0%0/1
$this_policies_arg->{"allow_to_the_right_of_a_fat_comma"} // 1
$this_policies_arg->{"allow_to_the_right_of_a_fat_comma"}
Truth table0%0/2
A
A= $this_policies_arg->{"allow_to_the_right_of_a_fat_comma"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | my $allowed_values = $this_policies_arg->{allowed_values}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | if (defined $allowed_values) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | delete $allowed_values{2}; # remove `2` from allowed list when allowed_values is specified | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | for my $allowed_value (split /\s+/, $allowed_values) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | my ($begin, $end) = split /[.][.]/, $allowed_value; # for range notation (e.g. `1..42`) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | if (defined $begin && defined $end) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $begin and defined $end
MC/DC0%0/2
defined $begin and defined $end
defined $begin
defined $end
Truth table0%0/3
A and B
A= defined $beginB= defined $end
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | # used range notation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | my ($delta) = $end =~ /:by [(] (.+) [)] \z/x; # for range notation with by (e.g. `-2.0..2.0:by(0.5)`) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | $delta //= 1; # default delta | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$delta //= 1
MC/DC0%0/1
$delta //= 1
$delta
Truth table0%0/2
A
A= $delta
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | for (my $num = $begin; $num <= $end; $num += $delta) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | $allowed_values{$num} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | # not used range notation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | $allowed_values{$allowed_value} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | my $allowed_types = $this_policies_arg->{allowed_types}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | if (defined $allowed_types) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | delete $allowed_types{Float}; # remove `Float` from allowed types list when allowed_types is specified | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | for my $allowed_type (split /\s+/, $allowed_types) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | $allowed_types{$allowed_type} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | my $constant_creator_subroutines = $this_policies_arg->{constant_creator_subroutines}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | if (defined $constant_creator_subroutines) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | for my $sub (split /\s+/, $constant_creator_subroutines) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | $constant_creator_subroutines{$sub} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 2 | my @violations; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 2 | ▶ | for (my $i = 0, my $token_type, my $token_data; my $token = $tokens->[$i]; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 21 | $is_readonly_array1_ctx = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 21 | $token_type = $token->{type}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 21 | $token_data = $token->{data}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 21 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition55%5/9
$token_type == 93 or $token_type == 71 or $token_type == 122 and $constant_creator_subroutines{$token_data}
$token_type == 93 or $token_type == 71
$token_type == 122 and $constant_creator_subroutines{$token_data}
MC/DC25%1/4
$token_type == 93 or $token_type == 71 or $token_type == 122 and $constant_creator_subroutines{$token_data}
$token_type == 93
$token_type == 71
$token_type == 122
$constant_creator_subroutines{$token_data}
Truth table40%2/5
A or B or C and D
A= $token_type == 93B= $token_type == 71C= $token_type == 122D= $constant_creator_subroutines{$token_data}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | $token_type == USE_DECL || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | $token_type == REQUIRE_DECL || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | ($token_type == KEY && $constant_creator_subroutines{$token_data}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 8 | ▶ | for ($i++; $token = $tokens->[$i]; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 24 | $token_type = $token->{type}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 24 | ▶ | if ($token_type == SEMI_COLON) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 8 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 8 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 13 | ▶ | if ($token_type == NAMESPACE && $token_data eq 'Readonly') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$token_type == 127 and $token_data eq "Readonly"
MC/DC0%0/2
$token_type == 127 and $token_data eq "Readonly"
$token_type == 127
$token_data eq "Readonly"
Truth table33%1/3
A and B
A= $token_type == 127B= $token_data eq "Readonly"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | $token = $tokens->[++$i] or last; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | if ($token->{type} == NAMESPACE_RESOLVER) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | $token = $tokens->[++$i] or last; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | $token_data = $token->{data}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | if ($token->{type} == NAMESPACE) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | if ($token_data eq 'Scalar' || $token_data eq 'Array') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$token_data eq "Scalar" or $token_data eq "Array"
MC/DC0%0/2
$token_data eq "Scalar" or $token_data eq "Array"
$token_data eq "Scalar"
$token_data eq "Array"
Truth table0%0/3
A or B
A= $token_data eq "Scalar"B= $token_data eq "Array"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | # when `Readonly::Scalar` or `Readonly::Array`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | # skip tokens to semi colon (means don't evaluate). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | for ($i++; $token = $tokens->[$i]; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | $token_type = $token->{type}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | if ($token_type == SEMI_COLON) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | elsif ($token_data eq 'Array1') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | # when `Readonly::Array1` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | $i += 2; # skip to assigning token | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | $token = $tokens->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | $token_type = $token->{type}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | $token_data = $token->{data}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | $is_readonly_array1_ctx = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | # no break! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | # for the $VERSION variable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 13 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition16%1/6
$token_data eq "\$VERSION" and $token_type == 166 || $token_type == 194
$token_type == 166 or $token_type == 194
MC/DC0%0/3
$token_data eq "\$VERSION" and $token_type == 166 || $token_type == 194
$token_data eq "\$VERSION"
$token_type == 166
$token_type == 194
Truth table25%1/4
A and B or C
A= $token_data eq "\$VERSION"B= $token_type == 166C= $token_type == 194
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | $token_data eq '$VERSION' && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | ($token_type == VAR || $token_type == GLOBAL_VAR) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | # skip to end of line. Don't evaluate it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | for ($i++; $token = $tokens->[$i]; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | last if $token->{type} == SEMI_COLON; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 13 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition22%2/9
$token_type == 65 or $token_type == 124 and !$allow_to_the_right_of_a_fat_comma || $is_readonly_array1_ctx
$token_type == 124 and !$allow_to_the_right_of_a_fat_comma || $is_readonly_array1_ctx
not $allow_to_the_right_of_a_fat_comma or $is_readonly_array1_ctx
MC/DC0%0/4
$token_type == 65 or $token_type == 124 and !$allow_to_the_right_of_a_fat_comma || $is_readonly_array1_ctx
$token_type == 65
$token_type == 124
not $allow_to_the_right_of_a_fat_comma
$is_readonly_array1_ctx
Truth table20%1/5
A or B and not(C) or D
A= $token_type == 65B= $token_type == 124C= not $allow_to_the_right_of_a_fat_commaD= $is_readonly_array1_ctx
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | $token_type == ASSIGN || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | ($token_type == ARROW && (!$allow_to_the_right_of_a_fat_comma || $is_readonly_array1_ctx)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | push @violations, @{$class->_scan(\$i)}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 13 | ▶ | if ($token_type == FUNCTION) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | $token = $tokens->[++$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | my $statement = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | my @statements = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | my $lbnum = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | for ($i++; $token = $tokens->[$i]; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | $token_type = $token->{type}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | if ($token_type == LEFT_BRACE) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | $lbnum++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | elsif ($token_type == RIGHT_BRACE) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | last if --$lbnum <= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | elsif ($token_type == SEMI_COLON) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | push @statements, $statement; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | $statement = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | push @$statement, $token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | ▶ | if (scalar @statements > 1) { # when exists multiple statements in function | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | my $last_statement = pop @statements; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | my $return_value_token = pop @$last_statement or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | if ($return_value_token->{type} == RETURN) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | ▶ | $return_value_token = pop @$last_statement or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | my $invalid_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | if ($return_value_token->{type} == INT) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | $invalid_token = $class->_validate_int_token($return_value_token); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | elsif ($return_value_token->{type} == DOUBLE) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | $invalid_token = $class->_validate_doble_token($return_value_token); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | if ($invalid_token) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | push @violations, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | filename => $file, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | line => $token->{line}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | description => DESC, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | explanation => EXPL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | policy => __PACKAGE__, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 13 | ▶ | if ($token_type == FOR_STATEMENT || $token_type == FOREACH_STATEMENT) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$token_type == 133 or $token_type == 134
MC/DC50%1/2
$token_type == 133 or $token_type == 134
$token_type == 133
$token_type == 134
Truth table66%2/3
A or B
A= $token_type == 133B= $token_type == 134
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 1 | ▶ | for ($i++; $token = $tokens->[$i]; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 6 | $token_type = $token->{type}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 6 | ▶ | if ($token_type == SEMI_COLON || $token_type == LEFT_BRACE) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$token_type == 106 or $token_type == 109
MC/DC50%1/2
$token_type == 106 or $token_type == 109
$token_type == 106
$token_type == 109
Truth table66%2/3
A or B
A= $token_type == 106B= $token_type == 109
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 1 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | elsif ($token_type == SLICE) { # e.g. for my $foo (1..42) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | ▶ | my $begin = $tokens->[$i-1] or last; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | my $end = $tokens->[$i+1] or last; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | ▶ | if ($begin->{type} == INT && $end->{type} == INT) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$begin->{"type"} == 170 and $end->{"type"} == 170
MC/DC0%0/2
$begin->{"type"} == 170 and $end->{"type"} == 170
$begin->{"type"} == 170
$end->{"type"} == 170
Truth table0%0/3
A and B
A= $begin->{"type"} == 170B= $end->{"type"} == 170
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | if (!$allowed_values{$begin->{data}} || !$allowed_values{$end->{data}}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$allowed_values{$begin->{"data"}} and $allowed_values{$end->{"data"}}
MC/DC0%0/2
$allowed_values{$begin->{"data"}} and $allowed_values{$end->{"data"}}
$allowed_values{$begin->{"data"}}
$allowed_values{$end->{"data"}}
Truth table0%0/3
A and B
A= $allowed_values{$begin->{"data"}}B= $allowed_values{$end->{"data"}}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | push @violations, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | filename => $file, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | line => $token->{line}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | description => DESC, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | explanation => EXPL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | policy => __PACKAGE__, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | # for index of array | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 12 | ▶ | if ($token_type == LEFT_BRACKET) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | ▶ | my $next_token = $tokens->[$i+1] or last; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | if ($next_token->{type} == INT) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | my $int_token = $next_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | $next_token = $tokens->[$i+2] or last; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | my $invalid_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | ▶ | if ($next_token->{type} == RIGHT_BRACKET) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | my $num = $int_token->{data} + 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | ▶ | if (!$allowed_values{$num} && $num ne -1) { # -1 is allowed specially when it is used as index of array | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $allowed_values{$num} and $num ne -1
MC/DC0%0/2
not $allowed_values{$num} and $num ne -1
not $allowed_values{$num}
$num ne -1
Truth table0%0/3
not(A) and B
A= not $allowed_values{$num}B= $num ne -1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | $invalid_token = $int_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | elsif ($next_token->{type} != COMMA) { # if it is not enumeration (probably it is any handling for index of array) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | $invalid_token = $next_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | ▶ | if ($invalid_token) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | push @violations, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | filename => $file, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | line => $invalid_token->{line}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | description => DESC, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | explanation => EXPL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | policy => __PACKAGE__, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 2 | return \@violations; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 3 | my $is_in_assigning_context; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | sub _scan { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_scan: not called CC=22 SCAR=62.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | my ($class, $i) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | ▶ | my $token = $tokens->[$$i] or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | my $token_type = $token->{type}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | my $token_data = $token->{data}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | ▶ | if ($token_type == ASSIGN) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | $is_in_assigning_context = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | ▶ | $token = $tokens->[++$$i] or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | $token_type = $token->{type}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | $token_data = $token->{data}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | elsif ($token_type == ARROW) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | $is_in_assigning_context = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | ▶ | if (!$allow_to_the_right_of_a_fat_comma || $is_readonly_array1_ctx) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $allow_to_the_right_of_a_fat_comma or $is_readonly_array1_ctx
MC/DC0%0/2
not $allow_to_the_right_of_a_fat_comma or $is_readonly_array1_ctx
not $allow_to_the_right_of_a_fat_comma
$is_readonly_array1_ctx
Truth table0%0/3
not(A) or B
A= not $allow_to_the_right_of_a_fat_commaB= $is_readonly_array1_ctx
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | $is_in_assigning_context = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | ▶ | $token = $tokens->[++$$i] or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | $token_type = $token->{type}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | $token_data = $token->{data}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | my $invalid_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | my @violations; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | ▶ | if ($token_type == DOUBLE) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | $invalid_token = $class->_validate_doble_token($token, $$i); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | elsif ($token_type == INT) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | $invalid_token = $class->_validate_int_token($token); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | elsif ($token_type == LEFT_PAREN) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | my $lpnum = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | ▶ | for ($$i++; $token = $tokens->[$$i]; $$i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | $token_type = $token->{type}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | ▶ | if ($token_type == LEFT_PAREN) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | $lpnum++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | elsif ($token_type == RIGHT_PAREN) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | ▶ | last if --$lpnum <= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | push @violations, @{$class->_scan($i)}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | elsif ($token_type == LEFT_BRACKET) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | my $lbnum = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | ▶ | for ($$i++; $token = $tokens->[$$i]; $$i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | $token_type = $token->{type}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | if ($token_type == LEFT_BRACKET) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | $lbnum++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | elsif ($token_type == RIGHT_BRACKET) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | ▶ | last if --$lbnum <= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | push @violations, @{$class->_scan($i)}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | ▶ | if ($is_in_assigning_context && $invalid_token) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$is_in_assigning_context and $invalid_token
MC/DC0%0/2
$is_in_assigning_context and $invalid_token
$is_in_assigning_context
$invalid_token
Truth table0%0/3
A and B
A= $is_in_assigning_contextB= $invalid_token
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | push @violations, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | filename => $file, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | line => $invalid_token->{line}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | description => DESC, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | explanation => EXPL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | policy => __PACKAGE__, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | return \@violations; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | ▶ | sub _validate_int_token { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_int_token: not called CC=13 SCAR=52.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | my ($class, $token) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | my $token_data = $token->{data}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | ▶ | if (my ($base_type) = $token_data =~ /\A[0-9]([b0xe]).+\z/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | ▶ | if ($1 eq 'b') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | ▶ | return $token if !$allowed_types{Binary}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | elsif ($1 eq '0') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | ▶ | return $token if !$allowed_types{Octal}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | elsif ($1 eq 'x') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | ▶ | return $token if !$allowed_types{Hex}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | elsif ($1 eq 'e') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | ▶ | return $token if !$allowed_types{Exp}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | ▶ | if (!$allowed_types{Int}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | return $token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | ▶ | if (!$allowed_values{all_integers} && !$allowed_values{$token_data+0}) { # `+0` to convert to number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$allowed_values{"all_integers"} or $allowed_values{$token_data + 0}
MC/DC0%0/2
$allowed_values{"all_integers"} or $allowed_values{$token_data + 0}
$allowed_values{"all_integers"}
$allowed_values{$token_data + 0}
Truth table0%0/3
A or B
A= $allowed_values{"all_integers"}B= $allowed_values{$token_data + 0}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | return $token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | ▶ | sub _validate_doble_token { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_doble_token: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | my ($class, $token, $i) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | my $token_data = $token->{data}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | ▶ | if ($i && $allowed_types{Float} && $allowed_values{$token_data+0}) { # `+0` to convert to number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/6
$i and $allowed_types{"Float"} and $allowed_values{$token_data + 0}
$i and $allowed_types{"Float"}
MC/DC0%0/3
$i and $allowed_types{"Float"} and $allowed_values{$token_data + 0}
$i
$allowed_types{"Float"}
$allowed_values{$token_data + 0}
Truth table0%0/4
A and B and C
A= $iB= $allowed_types{"Float"}C= $allowed_values{$token_data + 0}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | my $next_token = $tokens->[$i+1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | ▶ | if ($next_token && $next_token->{type} == DOUBLE) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$next_token and $next_token->{"type"} == 171
MC/DC0%0/2
$next_token and $next_token->{"type"} == 171
$next_token
$next_token->{"type"} == 171
Truth table0%0/3
A and B
A= $next_tokenB= $next_token->{"type"} == 171
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | return $next_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | ▶ | elsif (!$allowed_values{all_integers} || $token_data !~ /[.]0+\z/) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$allowed_values{'all_integers'} && $token_data =~ /[.]0+\z/
MC/DC0%0/2
$allowed_values{'all_integers'} && $token_data =~ /[.]0+\z/
$allowed_values{'all_integers'}
$token_data =~ /[.]0+\z/
Truth table0%0/3
A && B
A= $allowed_values{'all_integers'}B= $token_data =~ /[.]0+\z/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | return $token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||