Perl/Lint/Policy/CodeLayout/ProhibitParensWithBuiltins.pm

filter: Statementstmt 50.0% 29 / 58 Branchbran 14.7% 5 / 34 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 33.6% 41 / 122 CC 23 SCAR 55.8
CC
23
Cov
32%
evaluate
335.5
BEGIN
1.0
BEGIN
1.0
CRAP 266.3
« Perl/Lint/Policy/BuiltinFunctions/ProhibitVoidGrep.pm ↑ Summary Perl/Lint/Policy/Variables/ProhibitConditionalDeclarations.pm »
1 package Perl::Lint::Policy::CodeLayout::ProhibitParensWithBuiltins;
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 Perl::Lint::Constants::Kind;
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 => 'Builtin function called with parentheses',
10 EXPL => [13],
11 3 };
12  
13 3 my %named_unary_ops = (
14 alarm => 1,
15 glob => 1,
16 rand => 1,
17 caller => 1,
18 gmtime => 1,
19 readlink => 1,
20 chdir => 1,
21 hex => 1,
22 ref => 1,
23 chroot => 1,
24 int => 1,
25 require => 1,
26 cos => 1,
27 lc => 1,
28 return => 1,
29 defined => 1,
30 lcfirst => 1,
31 rmdir => 1,
32 delete => 1,
33 length => 1,
34 scalar => 1,
35 do => 1,
36 localtime => 1,
37 sin => 1,
38 eval => 1,
39 lock => 1,
40 sleep => 1,
41 exists => 1,
42 log => 1,
43 sqrt => 1,
44 exit => 1,
45 lstat => 1,
46 srand => 1,
47 getgrp => 1,
48 my => 1,
49 stat => 1,
50 gethostbyname => 1,
51 oct => 1,
52 uc => 1,
53 getnetbyname => 1,
54 ord => 1,
55 ucfirst => 1,
56 getprotobyname => 1,
57 quotemeta => 1,
58 umask => 1,
59 undef => 1,
60 sort => 1,
61 );
62  
63 2 ▶sub evaluate {
Subroutine evaluate: called CC=23 SCAR=58.2
Pod undocumented
64 2 my ($class, $file, $tokens, $src, $args) = @_;
65  
66 2 my @violations;
67 2 ▶ for (my $i = 0; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 50 2 52
68 50 my $token_type = $token->{type};
69  
70 50 ▶ if ($token_type == BUILTIN_FUNC) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 70) 1 49 50
71 1 my $func = $token->{data};
72  
73 1 $token = $tokens->[++$i];
74 1 ▶ if ($token->{type} == LEFT_PAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->{"type"} == 107) 0 1 1
75 # for unary operators with parens
76 0 ▶ if ($named_unary_ops{$func}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($named_unary_ops{$func}) 0 0 0
77 0 $token = $tokens->[++$i];
78  
79 0 ▶ if ($token->{type} == RIGHT_PAREN) { # no args
Branch: 1 branch
BranchTrueFalseTotal
if ($token->{"type"} == 108) 0 0 0
80 push @violations, {
81 filename => $file,
82 line => $token->{line},
83 0 description => DESC,
84 explanation => EXPL,
85 policy => __PACKAGE__,
86 };
87 0 next;
88 }
89  
90 0 my $left_paren_num = 1;
91 0 ▶ for (; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
92 0 my $token_type = $token->{type};
93  
94 0 ▶ if ($token_type == LEFT_PAREN) {
Branch: 3 branches
BranchTrueFalseTotal
if ($token_type == 107) { } 0 0 0
elsif ($token_type == 108) { } 0 0 0
elsif ($token_type == 104) { } 0 0 0
95 0 $left_paren_num++;
96 }
97 elsif ($token_type == RIGHT_PAREN) {
98 0 ▶ last if --$left_paren_num <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if --$left_paren_num <= 0 0 0 0
99 }
100 elsif ($token_type == COMMA) {
101 push @violations, {
102 filename => $file,
103 line => $token->{line},
104 0 description => DESC,
105 explanation => EXPL,
106 policy => __PACKAGE__,
107 };
108 0 last;
109 }
110 }
111 0 next;
112 }
113  
114 0 my $is_op_in_arg = 0;
115 0 my $left_paren_num = 1;
116 0 ▶ for ($i++; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
117 0 my $token_type = $token->{type};
118  
119 0 ▶ if ($token_type == LEFT_PAREN) {
Branch: 3 branches
BranchTrueFalseTotal
if ($token_type == 107) { } 0 0 0
elsif ($token_type == 108) { } 0 0 0
elsif ($token_type == 65 or $token->{'kind'} == 1) { } 0 0 0
120 0 $left_paren_num++;
121 }
122 elsif ($token_type == RIGHT_PAREN) {
123 0 ▶ last if --$left_paren_num <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if --$left_paren_num <= 0 0 0 0
124 }
125 ▶ elsif ($token_type == ASSIGN || $token->{kind} == KIND_OP) {
Condition0%0/3
$token_type == 65 or $token->{"kind"} == 1
l!l&&r!l&&!r
000
MC/DC0%0/2
$token_type == 65 or $token->{"kind"} == 1
$token_type == 65 $token->{"kind"} == 1
Truth table0%0/3
A or B
A= $token_type == 65B= $token->{"kind"} == 1
ABresult
1X1
011
000
126 0 $is_op_in_arg = 1;
127 }
128 }
129  
130 0 ▶ if ($is_op_in_arg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_op_in_arg) 0 0 0
131 0 next;
132 }
133  
134 0 $token = $tokens->[++$i];
135 0 my $token_data = $token->{data};
136 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($token->{"type"} == 104 or $token->{"kind"} == 1 and $token_data ne "and" and $token_data ne "or" and $token_data ne "xor") 0 0 0
Condition0%0/12
$token->{"type"} == 104 or $token->{"kind"} == 1 and $token_data ne "and" and $token_data ne "or" and $token_data ne "xor"
l!l&&r!l&&!r
000
$token->{"kind"} == 1 and $token_data ne "and" and $token_data ne "or" and $token_data ne "xor"
!ll&&!rl&&r
000
$token->{"kind"} == 1 and $token_data ne "and" and $token_data ne "or"
!ll&&!rl&&r
000
$token->{"kind"} == 1 and $token_data ne "and"
!ll&&!rl&&r
000
MC/DC0%0/5
$token->{"type"} == 104 or $token->{"kind"} == 1 and $token_data ne "and" and $token_data ne "or" and $token_data ne "xor"
$token->{"type"} == 104 $token->{"kind"} == 1 $token_data ne "and" $token_data ne "or" $token_data ne "xor"
Truth table0%0/6
A or B and C and D and E
A= $token->{"type"} == 104B= $token->{"kind"} == 1C= $token_data ne "and"D= $token_data ne "or"E= $token_data ne "xor"
ABCDEresult
1XXXX1
011111
00XXX0
010XX0
0110X0
011100
137 $token->{type} == COMMA ||
138 (
139 $token->{kind} == KIND_OP &&
140 $token_data ne 'and' && # XXX enough?
141 $token_data ne 'or' && # for low-precedence operator
142 $token_data ne 'xor' #
143 )
144 ) {
145 0 next;
146 }
147  
148 push @violations, {
149 filename => $file,
150 line => $token->{line},
151 0 description => DESC,
152 explanation => EXPL,
153 policy => __PACKAGE__,
154 };
155 }
156 }
157 }
158  
159 2 return \@violations;
160 }
161  
162 3 1;
« Perl/Lint/Policy/BuiltinFunctions/ProhibitVoidGrep.pm ↑ Summary Perl/Lint/Policy/Variables/ProhibitConditionalDeclarations.pm »