Perl/Lint/Policy/CodeLayout/ProhibitQuotedWordLists.pm

filter: Statementstmt 41.1% 28 / 68 Branchbran 17.3% 9 / 52 Conditioncond 18.1% 4 / 22 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 29.0% 47 / 162 CC 35 SCAR 63.7
CC
35
Cov
29%
evaluate
665.9
BEGIN
1.0
BEGIN
1.0
CRAP 582.8
« Perl/Lint/Policy/Modules/ProhibitExcessMainComplexity.pm ↑ Summary Perl/Lint/Policy/BuiltinFunctions/ProhibitComplexMappings.pm »
1 package Perl::Lint::Policy::CodeLayout::ProhibitQuotedWordLists;
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 ▶use Perl::Lint::Constants::Type;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use parent "Perl::Lint::Policy";
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 # TODO TODO TODO integrate duplicated functions between assign context and use context !!!!
8  
9 3 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 DESC => 'List of quoted literal words',
11 EXPL => 'Use "qw()" instead',
12 3 };
13  
14 2 ▶sub evaluate {
Subroutine evaluate: called CC=35 SCAR=65.0
Pod undocumented
15 2 my ($class, $file, $tokens, $src, $args) = @_;
16  
17 2 ▶ my $min_elements = $args->{prohibit_quoted_word_lists}->{min_elements} || 2;
Condition50%1/2
$args->{'prohibit_quoted_word_lists'}{'min_elements'} || 2
l!l
02
MC/DC0%0/1
$args->{'prohibit_quoted_word_lists'}{'min_elements'} || 2
$args->{'prohibit_quoted_word_lists'}{'min_elements'}
Truth table50%1/2
A
A= $args->{'prohibit_quoted_word_lists'}{'min_elements'}
Aresult
11
00
18 2 ▶ my $strict = $args->{prohibit_quoted_word_lists}->{strict} || 0;
Condition50%1/2
$args->{'prohibit_quoted_word_lists'}{'strict'} || 0
l!l
02
MC/DC0%0/1
$args->{'prohibit_quoted_word_lists'}{'strict'} || 0
$args->{'prohibit_quoted_word_lists'}{'strict'}
Truth table50%1/2
A
A= $args->{'prohibit_quoted_word_lists'}{'strict'}
Aresult
11
00
19  
20 2 my @violations;
21 2 ▶ for (my $i = 0; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 27 2 29
22 27 my $token_type = $token->{type};
23  
24 27 ▶ if (
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 168 or $token_type == 192 or $token_type == 195) { } 0 27 27
elsif ($token_type == 93) { } 8 19 27
Condition33%2/6
$token_type == 168 or $token_type == 192 or $token_type == 195
l!l&&r!l&&!r
0027
$token_type == 168 or $token_type == 192
l!l&&r!l&&!r
0027
MC/DC0%0/3
$token_type == 168 or $token_type == 192 or $token_type == 195
$token_type == 168 $token_type == 192 $token_type == 195
Truth table25%1/4
A or B or C
A= $token_type == 168B= $token_type == 192C= $token_type == 195
ABCresult
1XX1
01X1
0011
0000
25 $token_type == ARRAY_VAR ||
26 $token_type == LOCAL_ARRAY_VAR ||
27 $token_type == GLOBAL_ARRAY_VAR
28 ) {
29 0 $token = $tokens->[++$i];
30 0 $token_type = $token->{type};
31 0 ▶ if ($token_type == ASSIGN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 65) 0 0 0
32 0 $token = $tokens->[++$i];
33 0 $token_type = $token->{type};
34 0 ▶ if ($token_type == LEFT_PAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 107) 0 0 0
35 0 my $left_paren_num = 1;
36 0 my $is_violated = 1;
37 0 my $elem_num = 0;
38  
39 0 ▶ for ($i++; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
40 0 $token_type = $token->{type};
41 0 ▶ if ($token_type == LEFT_PAREN) {
Branch: 4 branches
BranchTrueFalseTotal
if ($token_type == 107) { } 0 0 0
elsif ($token_type == 108) { } 0 0 0
elsif ($token_type == 172 or $token_type == 173) { } 0 0 0
elsif ($token_type != 104) { } 0 0 0
42 0 $left_paren_num++;
43 }
44 elsif ($token_type == RIGHT_PAREN) {
45 0 ▶ if (--$left_paren_num <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (--$left_paren_num <= 0) 0 0 0
46 0 ▶ if ($is_violated && $elem_num >= $min_elements) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_violated and $elem_num >= $min_elements) 0 0 0
Condition0%0/3
$is_violated and $elem_num >= $min_elements
!ll&&!rl&&r
000
MC/DC0%0/2
$is_violated and $elem_num >= $min_elements
$is_violated $elem_num >= $min_elements
Truth table0%0/3
A and B
A= $is_violatedB= $elem_num >= $min_elements
ABresult
0X0
100
111
47 push @violations, {
48 filename => $file,
49 line => $token->{line},
50 0 description => DESC,
51 explanation => EXPL,
52 policy => __PACKAGE__
53 };
54 }
55 0 last;
56 }
57 }
58 ▶ elsif ($token_type == STRING || $token_type == RAW_STRING) {
Condition0%0/3
$token_type == 172 or $token_type == 173
l!l&&r!l&&!r
000
MC/DC0%0/2
$token_type == 172 or $token_type == 173
$token_type == 172 $token_type == 173
Truth table0%0/3
A or B
A= $token_type == 172B= $token_type == 173
ABresult
1X1
011
000
59 0 $elem_num++;
60  
61 0 ▶ next if $strict;
Branch: 1 branch
BranchTrueFalseTotal
if $strict 0 0 0
62  
63 0 ▶ if ($token->{data} !~ /\A[a-zA-Z-]+\Z/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($token->{"data"} =~ /\A[a-zA-Z-]+\Z/) 0 0 0
64 0 $is_violated = 0;
65 }
66 }
67 elsif ($token_type != COMMA) {
68 0 $elem_num++;
69 0 $is_violated = 0;
70 }
71 }
72 }
73 }
74 }
75 elsif ($token_type == USE_DECL) {
76 8 ▶ USE_STATEMENT: for ($i++; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 24 0 24
77 24 $token_type = $token->{type};
78  
79 24 ▶ if ($token_type == LEFT_PAREN) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 107) { } 0 24 24
elsif ($token_type == 106) { } 8 16 24
80 0 my $left_paren_num = 1;
81 0 my $is_violated = 1;
82 0 my $elem_num = 0;
83  
84 0 ▶ for ($i++; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
85 0 $token_type = $token->{type};
86 0 ▶ if ($token_type == LEFT_PAREN) {
Branch: 4 branches
BranchTrueFalseTotal
if ($token_type == 107) { } 0 0 0
elsif ($token_type == 108) { } 0 0 0
elsif ($token_type == 172 or $token_type == 173) { } 0 0 0
elsif ($token_type != 104) { } 0 0 0
87 0 $left_paren_num++;
88 }
89 elsif ($token_type == RIGHT_PAREN) {
90 0 ▶ if (--$left_paren_num <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (--$left_paren_num <= 0) 0 0 0
91 0 ▶ if ($is_violated && $elem_num >= $min_elements) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_violated and $elem_num >= $min_elements) 0 0 0
Condition0%0/3
$is_violated and $elem_num >= $min_elements
!ll&&!rl&&r
000
MC/DC0%0/2
$is_violated and $elem_num >= $min_elements
$is_violated $elem_num >= $min_elements
Truth table0%0/3
A and B
A= $is_violatedB= $elem_num >= $min_elements
ABresult
0X0
100
111
92 push @violations, {
93 filename => $file,
94 line => $token->{line},
95 0 description => DESC,
96 explanation => EXPL,
97 policy => __PACKAGE__,
98 };
99 }
100 0 last USE_STATEMENT;
101 }
102 }
103 ▶ elsif ($token_type == STRING || $token_type == RAW_STRING) {
Condition0%0/3
$token_type == 172 or $token_type == 173
l!l&&r!l&&!r
000
MC/DC0%0/2
$token_type == 172 or $token_type == 173
$token_type == 172 $token_type == 173
Truth table0%0/3
A or B
A= $token_type == 172B= $token_type == 173
ABresult
1X1
011
000
104 0 $elem_num++;
105  
106 0 ▶ next if $strict;
Branch: 1 branch
BranchTrueFalseTotal
if $strict 0 0 0
107  
108 0 ▶ if ($token->{data} !~ /\A[a-zA-Z-]+\Z/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($token->{"data"} =~ /\A[a-zA-Z-]+\Z/) 0 0 0
109 0 $is_violated = 0;
110 }
111 }
112 elsif ($token_type != COMMA) {
113 0 $elem_num++;
114 0 $is_violated = 0;
115 }
116 }
117 }
118 elsif ($token_type == SEMI_COLON) {
119 8 last;
120 }
121 }
122 }
123 }
124  
125 2 return \@violations;
126 }
127  
128 3 1;
129  
« Perl/Lint/Policy/Modules/ProhibitExcessMainComplexity.pm ↑ Summary Perl/Lint/Policy/BuiltinFunctions/ProhibitComplexMappings.pm »