Perl/Lint/Policy/ValuesAndExpressions/ProhibitLeadingZeros.pm

filter: Statementstmt 19.2% 16 / 83 Branchbran 0.0% 0 / 56 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 1 totaltotal 12.8% 21 / 163 CC 33 SCAR 68.8
CC
33
Cov
11%
evaluate
1122.0
BEGIN
1.0
BEGIN
1.0
CRAP 974.5
« Perl/Lint/Policy/Variables/ProhibitPunctuationVars.pm ↑ Summary Perl/Lint/Policy/Variables/ProhibitEvilVariables.pm »
1 package Perl::Lint::Policy::ValuesAndExpressions::ProhibitLeadingZeros;
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 Perl::Lint::Constants::Type;
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{Don't allow any leading zeros at all. Otherwise builtins that deal with Unix permissions, e.g. chmod, don't get flagged.},
9 EXPL => [58],
10 2 };
11  
12 0 ▶sub evaluate {
Subroutine evaluate: not called CC=33 SCAR=70.2
Pod undocumented
13 0 my ($class, $file, $tokens, $src, $args) = @_;
14  
15 0 my $is_strict;
16 0 ▶ if (my $this_policies_arg = $args->{prohibit_leading_zeros}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $this_policies_arg = $args->{"prohibit_leading_zeros"}) 0 0 0
17 0 $is_strict = $this_policies_arg->{strict};
18 }
19  
20 0 my @violations;
21 0 ▶ for (my $i = 0; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
22 0 my $token_type = $token->{type};
23 0 my $token_data = $token->{data};
24  
25 0 ▶ if (!$is_strict && $token_type == BUILTIN_FUNC) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $is_strict and $token_type == 70) 0 0 0
Condition0%0/3
not $is_strict and $token_type == 70
!ll&&!rl&&r
000
MC/DC0%0/2
not $is_strict and $token_type == 70
not $is_strict $token_type == 70
Truth table0%0/3
not(A) and B
A= not $is_strictB= $token_type == 70
ABresult
0X0
100
111
26 # skip the first argument of chmod()
27 0 ▶ if ($token_data eq 'chmod') {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_data eq "chmod") 0 0 0
28 0 ▶ if ($tokens->[++$i]->{type} == LEFT_PAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$tokens[++$i]{"type"} == 107) 0 0 0
29 0 $i++;
30 }
31 0 next;
32 }
33  
34 # skip third argument of dbmopen()
35 0 ▶ if ($token_data eq 'dbmopen') {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_data eq "dbmopen") 0 0 0
36 0 ▶ if ($tokens->[++$i]->{type} == LEFT_PAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$tokens[++$i]{"type"} == 107) 0 0 0
37 0 $i++;
38 }
39  
40 0 my $comma_num = 0;
41 0 ▶ for ($i++; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
42 0 $token_type = $token->{type};
43  
44 0 ▶ if ($token_type == SEMI_COLON) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 106) 0 0 0
45 0 last;
46 }
47  
48 0 ▶ if ($token_type == COMMA) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 104) 0 0 0
49 0 $comma_num++;
50 }
51  
52 0 ▶ if ($comma_num == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($comma_num == 2) 0 0 0
53 0 $i++;
54 0 last;
55 }
56 }
57 0 next;
58 }
59  
60 # skip second argument of mkdir()
61 0 ▶ if ($token_data eq 'mkdir') {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_data eq "mkdir") 0 0 0
62 0 ▶ if ($tokens->[++$i]->{type} == LEFT_PAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$tokens[++$i]{"type"} == 107) 0 0 0
63 0 $i++;
64 }
65  
66 0 my $comma_num = 0;
67 0 ▶ for ($i++; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
68 0 $token_type = $token->{type};
69  
70 0 ▶ if ($token_type == SEMI_COLON) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 106) 0 0 0
71 0 last;
72 }
73  
74 0 ▶ if ($token_type == COMMA) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 104) 0 0 0
75 0 $comma_num++;
76 }
77  
78 0 ▶ if ($comma_num == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($comma_num == 1) 0 0 0
79 0 $i++;
80 0 last;
81 }
82 }
83 0 next;
84 }
85  
86 # skip the first argument of umask()
87 0 ▶ if ($token_data eq 'umask') {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_data eq "umask") 0 0 0
88 0 ▶ if ($tokens->[++$i]->{type} == LEFT_PAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$tokens[++$i]{"type"} == 107) 0 0 0
89 0 $i++;
90 }
91 0 next;
92 }
93 }
94  
95 0 ▶ if (!$is_strict && $token_type == KEY) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $is_strict and $token_type == 122) 0 0 0
Condition0%0/3
not $is_strict and $token_type == 122
!ll&&!rl&&r
000
MC/DC0%0/2
not $is_strict and $token_type == 122
not $is_strict $token_type == 122
Truth table0%0/3
not(A) and B
A= not $is_strictB= $token_type == 122
ABresult
0X0
100
111
96 # skip the fourth argument of sysopen()
97 0 ▶ if ($token_data eq 'sysopen') {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_data eq "sysopen") 0 0 0
98 0 ▶ if ($tokens->[++$i]->{type} == LEFT_PAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$tokens[++$i]{"type"} == 107) 0 0 0
99 0 $i++;
100 }
101  
102 0 my $comma_num = 0;
103 0 ▶ for ($i++; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
104 0 $token_type = $token->{type};
105  
106 0 ▶ if ($token_type == SEMI_COLON) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 106) 0 0 0
107 0 last;
108 }
109  
110 0 ▶ if ($token_type == COMMA) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 104) 0 0 0
111 0 $comma_num++;
112 }
113  
114 0 ▶ if ($comma_num == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($comma_num == 3) 0 0 0
115 0 $i++;
116 0 last;
117 }
118 }
119 0 next;
120 }
121 }
122  
123 0 ▶ if ($token_type == INT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 170) 0 0 0
124 0 my $int = $token_data;
125 0 $int =~ s/_//g;
126 0 ▶ if ($int =~ /\A-?0/ && (eval($int) // 0) != 0) { ## no critic: to accept bin, oct and hex decimal
Branch: 1 branch
BranchTrueFalseTotal
if ($int =~ /\A-?0/ and (eval $int // 0) != 0) 0 0 0
Condition0%0/5
$int =~ /\A-?0/ and (eval $int // 0) != 0
!ll&&!rl&&r
000
eval $int // 0
l!l
00
MC/DC0%0/2
$int =~ /\A-?0/ and (eval $int // 0) != 0
$int =~ /\A-?0/ eval $int
Truth table0%0/3
A and B
A= $int =~ /\A-?0/B= eval $int
ABresult
0X0
100
111
127 push @violations, {
128 filename => $file,
129 line => $token->{line},
130 0 description => DESC,
131 explanation => EXPL,
132 policy => __PACKAGE__,
133 };
134 }
135 0 next;
136 }
137 }
138  
139 0 return \@violations;
140 }
141  
142 2 1;
143  
« Perl/Lint/Policy/Variables/ProhibitPunctuationVars.pm ↑ Summary Perl/Lint/Policy/Variables/ProhibitEvilVariables.pm »