Perl/Lint/Policy/NamingConventions/ProhibitAmbiguousNames.pm

filter: Statementstmt 34.9% 22 / 63 Branchbran 0.0% 0 / 34 Conditioncond 0.0% 0 / 30 MC/DCmcdc 0.0% 0 / 16 Subroutinesub 87.5% 7 / 8 Podpod 0.0% 0 / 1 totaltotal 19.0% 29 / 152 CC 30 SCAR 66.3
CC
30
Cov
17%
evaluate
930.0
BEGIN
1.0
BEGIN
1.0
CRAP 754.2
« Perl/Lint/Policy/Variables/RequireNegativeIndices.pm ↑ Summary Perl/Lint/Policy/Subroutines/ProhibitManyArgs.pm »
1 package Perl::Lint::Policy::NamingConventions::ProhibitAmbiguousNames;
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 String::CamelCase qw/wordsplit/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Perl::Lint::Constants::Type;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use parent "Perl::Lint::Policy";
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use constant DEFAULT_FORBIDDEN_WORDS => [qw/abstract bases close contract last left no record right second set/];
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 DESC => 'The variable names that are not to be allowed',
12 EXPL => [48],
13 2 };
14  
15 0 ▶sub evaluate {
Subroutine evaluate: not called CC=30 SCAR=68.4
Pod undocumented
16 0 my ($class, $file, $tokens, $src, $args) = @_;
17  
18 0 my @forbidden_words = @{+DEFAULT_FORBIDDEN_WORDS};
19 0 ▶ if (defined(my $forbiddens = $args->{prohibit_ambiguous_names}->{forbid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $forbiddens = $args->{"prohibit_ambiguous_names"}{"forbid"})) 0 0 0
20 0 @forbidden_words = split / /, $forbiddens;
21 }
22  
23 0 my @violations;
24 0 my $token_num = scalar @$tokens;
25 0 ▶ for (my $i = 0; $i < $token_num; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $token_num) 0 0 0
26 0 my $token = $tokens->[$i];
27 0 my $token_type = $token->{type};
28  
29 0 ▶ if ($token_type == FOR_STATEMENT || $token_type == FOREACH_STATEMENT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 133 or $token_type == 134) 0 0 0
Condition0%0/3
$token_type == 133 or $token_type == 134
l!l&&r!l&&!r
000
MC/DC0%0/2
$token_type == 133 or $token_type == 134
$token_type == 133 $token_type == 134
Truth table0%0/3
A or B
A= $token_type == 133B= $token_type == 134
ABresult
1X1
011
000
30 0 my $next_token_type = $tokens->[++$i]->{type};
31 0 ▶ $i++ if $next_token_type == VAR_DECL || $next_token_type == OUR_DECL;
Branch: 1 branch
BranchTrueFalseTotal
if $next_token_type == 62 or $next_token_type == 91 0 0 0
Condition0%0/3
$next_token_type == 62 or $next_token_type == 91
l!l&&r!l&&!r
000
MC/DC0%0/2
$next_token_type == 62 or $next_token_type == 91
$next_token_type == 62 $next_token_type == 91
Truth table0%0/3
A or B
A= $next_token_type == 62B= $next_token_type == 91
ABresult
1X1
011
000
32 0 $i++;
33 0 next;
34 }
35  
36 0 my @word_blocks;
37 0 ▶ if ($token_type == VAR_DECL || $token_type == OUR_DECL || $token_type == LOCAL_DECL) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 62 or $token_type == 91 or $token_type == 90) { } 0 0 0
elsif ($token_type == 63) { } 0 0 0
Condition0%0/6
$token_type == 62 or $token_type == 91 or $token_type == 90
l!l&&r!l&&!r
000
$token_type == 62 or $token_type == 91
l!l&&r!l&&!r
000
MC/DC0%0/3
$token_type == 62 or $token_type == 91 or $token_type == 90
$token_type == 62 $token_type == 91 $token_type == 90
Truth table0%0/4
A or B or C
A= $token_type == 62B= $token_type == 91C= $token_type == 90
ABCresult
1XX1
01X1
0011
0000
38 0 my $left_paren_num = 0;
39 0 ▶ for ($i++; $i < $token_num; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $token_num) 0 0 0
40 0 my $token = $tokens->[$i];
41 0 my $token_type = $token->{type};
42  
43 0 ▶ if (
Branch: 6 branches
BranchTrueFalseTotal
if ($token_type == 166 or $token_type == 191 or $token_type == 192 or $token_type == 193 or $token_type == 194) { } 0 0 0
elsif ($token_type == 126 or $token_type == 11) { } 0 0 0
elsif ($token_type == 127) { } 0 0 0
elsif ($token_type == 107) { } 0 0 0
elsif ($token_type == 108) { } 0 0 0
elsif ($left_paren_num <= 0) { } 0 0 0
Condition0%0/12
$token_type == 166 or $token_type == 191 or $token_type == 192 or $token_type == 193 or $token_type == 194
l!l&&r!l&&!r
000
$token_type == 166 or $token_type == 191 or $token_type == 192 or $token_type == 193
l!l&&r!l&&!r
000
$token_type == 166 or $token_type == 191 or $token_type == 192
l!l&&r!l&&!r
000
$token_type == 166 or $token_type == 191
l!l&&r!l&&!r
000
MC/DC0%0/5
$token_type == 166 or $token_type == 191 or $token_type == 192 or $token_type == 193 or $token_type == 194
$token_type == 166 $token_type == 191 $token_type == 192 $token_type == 193 $token_type == 194
Truth table0%0/6
A or B or C or D or E
A= $token_type == 166B= $token_type == 191C= $token_type == 192D= $token_type == 193E= $token_type == 194
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
44 $token_type == VAR ||
45 $token_type == LOCAL_VAR ||
46 $token_type == LOCAL_ARRAY_VAR ||
47 $token_type == LOCAL_HASH_VAR ||
48 $token_type == GLOBAL_VAR
49 ) {
50 0 push @word_blocks, [wordsplit(substr $token->{data}, 1)];
51 }
52 ▶ elsif ($token_type == NAMESPACE_RESOLVER || $token_type == GLOB) {
Condition0%0/3
$token_type == 126 or $token_type == 11
l!l&&r!l&&!r
000
MC/DC0%0/2
$token_type == 126 or $token_type == 11
$token_type == 126 $token_type == 11
Truth table0%0/3
A or B
A= $token_type == 126B= $token_type == 11
ABresult
1X1
011
000
53 0 next;
54 }
55 elsif ($token_type == NAMESPACE) {
56 0 push @word_blocks, [$tokens->[$i]->{data}];
57 }
58 elsif ($token_type == LEFT_PAREN) {
59 0 $left_paren_num++;
60 }
61 elsif ($token_type == RIGHT_PAREN) {
62 0 $left_paren_num--;
63 }
64 elsif ($left_paren_num <= 0) {
65 0 last;
66 }
67 }
68 }
69 elsif ($token_type == FUNCTION_DECL) {
70 0 ▶ for ($i++; $i < $token_num; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $token_num) 0 0 0
71 0 my $token = $tokens->[$i];
72 0 my $token_type = $token->{type};
73  
74 0 ▶ if ($token_type == FUNCTION || $token_type == NAMESPACE) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 203 or $token_type == 127) { } 0 0 0
elsif ($token_type == 109) { } 0 0 0
Condition0%0/3
$token_type == 203 or $token_type == 127
l!l&&r!l&&!r
000
MC/DC0%0/2
$token_type == 203 or $token_type == 127
$token_type == 203 $token_type == 127
Truth table0%0/3
A or B
A= $token_type == 203B= $token_type == 127
ABresult
1X1
011
000
75 0 push @word_blocks, [$token->{data}];
76 }
77 elsif ($token_type == LEFT_BRACE) {
78 0 last;
79 }
80 }
81 }
82  
83 0 for my $word_block (@word_blocks) {
84 0 for my $word (@$word_block) {
85 0 ▶ if (grep {$_ eq $word} @forbidden_words) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq $word;} @forbidden_words) 0 0 0
86 push @violations, {
87 filename => $file,
88 line => $token->{line},
89 0 description => DESC,
90 explanation => EXPL,
91 policy => __PACKAGE__,
92 };
93 0 last;
94 }
95 }
96 }
97 }
98  
99 0 return \@violations;
100 }
101  
102 2 1;
103  
« Perl/Lint/Policy/Variables/RequireNegativeIndices.pm ↑ Summary Perl/Lint/Policy/Subroutines/ProhibitManyArgs.pm »