Perl/Lint/Policy/Variables/ProhibitReusedNames.pm

filter: Statementstmt 26.4% 23 / 87 Branchbran 0.0% 0 / 36 Conditioncond 0.0% 0 / 20 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 58.3% 7 / 12 Podpod 0.0% 0 / 1 totaltotal 17.9% 30 / 167 CC 26 SCAR 62.0
CC
26
Cov
16%
evaluate
702.0
__ANON__
2.0
__ANON__
2.0
CRAP 493.7
« Perl/Lint/Policy/BuiltinFunctions/ProhibitComplexMappings.pm ↑ Summary Perl/Lint/Policy/Subroutines/ProhibitReturnSort.pm »
1 package Perl::Lint::Policy::Variables::ProhibitReusedNames;
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 List::Flatten ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use List::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Perl::Lint::Constants::Type;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use parent "Perl::Lint::Policy";
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 DESC => 'Reused variable name in lexical scope: ',
11 EXPL => 'Invent unique variable names',
12 2 };
13  
14 2 my %var_token_types = (
15 &LOCAL_VAR => 1,
16 &LOCAL_ARRAY_VAR => 1,
17 &LOCAL_HASH_VAR => 1,
18 &GLOBAL_VAR => 1,
19 &GLOBAL_ARRAY_VAR => 1,
20 &GLOBAL_HASH_VAR => 1,
21 &VAR => 1,
22 &ARRAY_VAR => 1,
23 &HASH_VAR => 1,
24 );
25  
26 0 ▶sub evaluate {
Subroutine evaluate: not called CC=26 SCAR=65.5
Pod undocumented
27 0 my ($class, $file, $tokens, $src, $args) = @_;
28  
29 0 my @allows = qw/$self $class/;
30 0 ▶ if (my $this_policies_arg = $args->{prohibit_reused_names}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $this_policies_arg = $args->{"prohibit_reused_names"}) 0 0 0
31 0 ▶ push @allows, split(/\s+/, $this_policies_arg->{allow} || '');
Condition0%0/2
$this_policies_arg->{'allow'} || ''
l!l
00
MC/DC0%0/1
$this_policies_arg->{'allow'} || ''
$this_policies_arg->{'allow'}
Truth table0%0/2
A
A= $this_policies_arg->{'allow'}
Aresult
11
00
32 }
33  
34 0 my @violations;
35  
36 0 my $depth = 0;
37 0 my @local_vars_by_depth = ([]);
38 0 ▶ for (my $i = 0, my $token_type; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
39 0 $token_type = $token->{type};
40 0 ▶ if ($token_type == LEFT_BRACE
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 109 or $token_type == 114 or $token_type == 113 or $token_type == 115) 0 0 0
Condition0%0/9
$token_type == 109 or $token_type == 114 or $token_type == 113 or $token_type == 115
l!l&&r!l&&!r
000
$token_type == 109 or $token_type == 114 or $token_type == 113
l!l&&r!l&&!r
000
$token_type == 109 or $token_type == 114
l!l&&r!l&&!r
000
MC/DC0%0/4
$token_type == 109 or $token_type == 114 or $token_type == 113 or $token_type == 115
$token_type == 109 $token_type == 114 $token_type == 113 $token_type == 115
Truth table0%0/5
A or B or C or D
A= $token_type == 109B= $token_type == 114C= $token_type == 113D= $token_type == 115
ABCDresult
1XXX1
01XX1
001X1
00011
00000
41 || $token_type == HASH_DEREFERENCE
42 || $token_type == ARRAY_DEREFERENCE
43 || $token_type == SCALAR_DEREFERENCE
44 ) {
45 0 $depth++;
46 0 push @local_vars_by_depth, [];
47 0 next;
48 }
49  
50 0 ▶ if ($token_type == RIGHT_BRACE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 110) 0 0 0
51 0 pop @local_vars_by_depth;
52 0 $depth--;
53 0 next;
54 }
55  
56 0 ▶ if ($token_type == PACKAGE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 128) 0 0 0
57 0 $local_vars_by_depth[$depth] = [];
58 0 next;
59 }
60  
61 0 ▶ if ($token_type == VAR_DECL || $token_type == OUR_DECL) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 62 or $token_type == 91) 0 0 0
Condition0%0/3
$token_type == 62 or $token_type == 91
l!l&&r!l&&!r
000
MC/DC0%0/2
$token_type == 62 or $token_type == 91
$token_type == 62 $token_type == 91
Truth table0%0/3
A or B
A= $token_type == 62B= $token_type == 91
ABresult
1X1
011
000
62 0 $i++;
63 0 $token = $tokens->[$i];
64 0 $token_type = $token->{type};
65  
66 0 my @vars;
67 0 ▶ if ($token_type == LEFT_PAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 107) 0 0 0
68 0 my $lpnum = 1;
69 0 ▶ for ($i++; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
70 0 $token_type = $token->{type};
71  
72 0 ▶ if ($token_type == LEFT_PAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 107) 0 0 0
73 0 $lpnum++;
74 0 next;
75 }
76  
77 0 ▶ if ($token_type == RIGHT_PAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 108) 0 0 0
78 0 ▶ last if --$lpnum <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if --$lpnum <= 0 0 0 0
79 0 next;
80 }
81  
82 0 ▶ if ($var_token_types{$token_type}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($var_token_types{$token_type}) 0 0 0
83 0 my $token_data = $token->{data};
84 0 ▶ if (List::Util::any { $_ eq $token_data } @allows) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if (&List::Util::any(sub { $_ eq $token_data; } , @allows)) 0 0 0
85 0 next;
86 }
87  
88 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (&List::Util::any(sub { $_ eq $token_data; } , &List::Flatten::flat(@local_vars_by_depth))) 0 0 0
89 0 ▶ List::Util::any {
Subroutine __ANON__: not called CC=1 SCAR=6.9
90 0 $_ eq $token_data
91 } List::Flatten::flat(@local_vars_by_depth)
92 ) {
93 push @violations, {
94 filename => $file,
95 line => $token->{line},
96 0 description => DESC . $token_data,
97 explanation => EXPL,
98 policy => __PACKAGE__,
99 };
100 0 next;
101 }
102  
103 # XXX
104 0 ▶ if ($depth < 0 && scalar @local_vars_by_depth < -$depth) {
Branch: 1 branch
BranchTrueFalseTotal
if ($depth < 0 and scalar @local_vars_by_depth < -$depth) 0 0 0
Condition0%0/3
$depth < 0 and scalar @local_vars_by_depth < -$depth
!ll&&!rl&&r
000
MC/DC0%0/2
$depth < 0 and scalar @local_vars_by_depth < -$depth
$depth < 0 scalar @local_vars_by_depth < -$depth
Truth table0%0/3
A and B
A= $depth < 0B= scalar @local_vars_by_depth < -$depth
ABresult
0X0
100
111
105 0 next;
106 }
107 0 push @{$local_vars_by_depth[$depth]}, $token_data;
108 0 next;
109 }
110 }
111 0 next;
112 }
113  
114 0 my $token_data = $token->{data};
115  
116 0 ▶ if (List::Util::any { $_ eq $token_data } @allows) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if (&List::Util::any(sub { $_ eq $token_data; } , @allows)) 0 0 0
117 0 next;
118 }
119  
120 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (&List::Util::any(sub { $_ eq $token_data; } , &List::Flatten::flat(@local_vars_by_depth))) 0 0 0
121 0 ▶ List::Util::any {
Subroutine __ANON__: not called CC=1 SCAR=6.9
122 0 $_ eq $token_data
123 } List::Flatten::flat(@local_vars_by_depth)
124 ) {
125 push @violations, {
126 filename => $file,
127 line => $token->{line},
128 0 description => DESC,
129 explanation => EXPL,
130 policy => __PACKAGE__,
131 };
132 0 next;
133 }
134  
135 # XXX
136 0 ▶ if ($depth < 0 && scalar @local_vars_by_depth < -$depth) {
Branch: 1 branch
BranchTrueFalseTotal
if ($depth < 0 and scalar @local_vars_by_depth < -$depth) 0 0 0
Condition0%0/3
$depth < 0 and scalar @local_vars_by_depth < -$depth
!ll&&!rl&&r
000
MC/DC0%0/2
$depth < 0 and scalar @local_vars_by_depth < -$depth
$depth < 0 scalar @local_vars_by_depth < -$depth
Truth table0%0/3
A and B
A= $depth < 0B= scalar @local_vars_by_depth < -$depth
ABresult
0X0
100
111
137 0 next;
138 }
139  
140 0 push @{$local_vars_by_depth[$depth]}, $token_data;
141 0 next;
142 }
143 }
144  
145 0 return \@violations;
146 }
147  
148 2 1;
149  
« Perl/Lint/Policy/BuiltinFunctions/ProhibitComplexMappings.pm ↑ Summary Perl/Lint/Policy/Subroutines/ProhibitReturnSort.pm »