Perl/Lint/Policy/InputOutput/RequireCheckedOpen.pm

filter: Statementstmt 17.2% 19 / 110 Branchbran 0.0% 0 / 94 Conditioncond 0.0% 0 / 48 MC/DCmcdc 0.0% 0 / 27 Subroutinesub 85.7% 6 / 7 Podpod 0.0% 0 / 1 totaltotal 8.7% 25 / 287 CC 64 SCAR 82.4
CC
64
Cov
8%
evaluate
4160.0
BEGIN
1.0
BEGIN
1.0
CRAP 3803.5
« Perl/Lint/Policy/InputOutput/RequireBriefOpen.pm ↑ Summary Perl/Lint/Policy/ErrorHandling/RequireCarping.pm »
1 package Perl::Lint::Policy::InputOutput::RequireCheckedOpen;
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 Perl::Lint::Constants::Kind;
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 {
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 DESC => 'Return value of "open" ignored',
10 EXPL => 'Check the return value of "open" for success',
11 2 };
12  
13 0 ▶sub evaluate {
Subroutine evaluate: not called CC=64 SCAR=83.3
Pod undocumented
14 0 my ($class, $file, $tokens, $src, $args) = @_;
15  
16 0 my $is_in_assign_context = 0;
17 0 my $is_in_statement_context = 0;
18 0 my $is_called_open_in_void = 0;
19 0 my $is_enabled_autodie = 0;
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_kind = $token->{kind};
24 0 my $token_data = $token->{data};
25  
26 0 ▶ if ($token_type == ASSIGN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 65) 0 0 0
27 0 $is_in_assign_context = 1;
28 0 next;
29 }
30  
31 0 ▶ if ($token_type == USED_NAME) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 94) 0 0 0
32 0 ▶ if ($token_data eq 'Fatal') {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_data eq 'Fatal') { } 0 0 0
elsif ($token_data eq 'autodie') { } 0 0 0
33 0 my $next_token = $tokens->[$i+1];
34 0 my $next_token_type = $next_token->{type};
35 0 ▶ if ($next_token_type == REG_LIST) {
Branch: 3 branches
BranchTrueFalseTotal
if ($next_token_type == 147) { } 0 0 0
elsif ($next_token_type == 107) { } 0 0 0
elsif ($next_token_type == 172 || $next_token_type == 173 and $next_token->{'data'} eq 'open') { } 0 0 0
36 0 ▶ for ($i += 3; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
37 0 my $token_type = $token->{type};
38 0 ▶ if ($token_type == REG_EXP && $token->{data} eq 'open') {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 187 and $token->{'data'} eq 'open') { } 0 0 0
elsif ($token_type == 151) { } 0 0 0
Condition0%0/3
$token_type == 187 and $token->{"data"} eq "open"
!ll&&!rl&&r
000
MC/DC0%0/2
$token_type == 187 and $token->{"data"} eq "open"
$token_type == 187 $token->{"data"} eq "open"
Truth table0%0/3
A and B
A= $token_type == 187B= $token->{"data"} eq "open"
ABresult
0X0
100
111
39 0 return [];
40 }
41 elsif ($token_type == REG_DELIM) {
42 0 last;
43 }
44 }
45 }
46 elsif ($next_token_type == LEFT_PAREN) {
47 0 my $left_paren_num = 1;
48 0 ▶ for ($i += 2; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
49 0 my $token_type = $token->{type};
50 0 ▶ if ($token_type == LEFT_PAREN) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 107) { } 0 0 0
elsif ($token_type == 172 || $token_type == 173 and $token->{'data'} eq 'open') { } 0 0 0
51 0 $left_paren_num++;
52 }
53 ▶ elsif (($token_type == STRING || $token_type == RAW_STRING) && $token->{data} eq 'open') {
Condition0%0/6
$token_type == 172 || $token_type == 173 and $token->{"data"} eq "open"
!ll&&!rl&&r
000
$token_type == 172 or $token_type == 173
l!l&&r!l&&!r
000
MC/DC0%0/3
$token_type == 172 || $token_type == 173 and $token->{"data"} eq "open"
$token_type == 172 $token_type == 173 $token->{"data"} eq "open"
Truth table0%0/5
A or B and C
A= $token_type == 172B= $token_type == 173C= $token->{"data"} eq "open"
ABCresult
00X0
1X00
0100
1X11
0111
54 0 return [];
55 }
56 else {
57 0 ▶ last if --$left_paren_num <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if --$left_paren_num <= 0 0 0 0
58 }
59 }
60 }
61 ▶ elsif (($next_token_type == STRING || $next_token_type == RAW_STRING) && $next_token->{data} eq 'open') {
Condition0%0/6
$next_token_type == 172 || $next_token_type == 173 and $next_token->{"data"} eq "open"
!ll&&!rl&&r
000
$next_token_type == 172 or $next_token_type == 173
l!l&&r!l&&!r
000
MC/DC0%0/3
$next_token_type == 172 || $next_token_type == 173 and $next_token->{"data"} eq "open"
$next_token_type == 172 $next_token_type == 173 $next_token->{"data"} eq "open"
Truth table0%0/5
A or B and C
A= $next_token_type == 172B= $next_token_type == 173C= $next_token->{"data"} eq "open"
ABCresult
00X0
1X00
0100
1X11
0111
62 0 last;
63 }
64 }
65 elsif ($token_data eq 'autodie') {
66 0 ▶ if ($tokens->[$i+1]->{type} == REG_LIST) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$tokens[$i + 1]{'type'} == 147) { } 0 0 0
67 0 ▶ for ($i += 3; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
68 0 my $token_type = $token->{type};
69 0 ▶ if ($token_type == REG_EXP && $token->{data} =~ /\A\s*:io\s*\Z/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 187 and $token->{'data'} =~ /\A\s*:io\s*\Z/) { } 0 0 0
elsif ($token_type == 151) { } 0 0 0
Condition0%0/3
$token_type == 187 and $token->{"data"} =~ /\A\s*:io\s*\Z/
!ll&&!rl&&r
000
MC/DC0%0/2
$token_type == 187 and $token->{"data"} =~ /\A\s*:io\s*\Z/
$token_type == 187 $token->{"data"} =~ /\A\s*:io\s*\Z/
Truth table0%0/3
A and B
A= $token_type == 187B= $token->{"data"} =~ /\A\s*:io\s*\Z/
ABresult
0X0
100
111
70 0 $is_enabled_autodie = 1;
71 }
72 elsif ($token_type == REG_DELIM) {
73 0 last;
74 }
75 }
76 }
77 else {
78 0 $is_enabled_autodie = 1;
79 }
80 }
81  
82 0 next;
83 }
84  
85 0 ▶ if ($token_type == NAMESPACE && $token_data eq 'Fatal') {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 127 and $token_data eq "Fatal") 0 0 0
Condition0%0/3
$token_type == 127 and $token_data eq "Fatal"
!ll&&!rl&&r
000
MC/DC0%0/2
$token_type == 127 and $token_data eq "Fatal"
$token_type == 127 $token_data eq "Fatal"
Truth table0%0/3
A and B
A= $token_type == 127B= $token_data eq "Fatal"
ABresult
0X0
100
111
86 0 my $skipped_token = $tokens->[$i+2];
87 0 ▶ if ($skipped_token && $skipped_token->{type} == NAMESPACE && $skipped_token->{data} eq 'Exception') {
Branch: 1 branch
BranchTrueFalseTotal
if ($skipped_token and $skipped_token->{"type"} == 127 and $skipped_token->{"data"} eq "Exception") 0 0 0
Condition0%0/6
$skipped_token and $skipped_token->{"type"} == 127 and $skipped_token->{"data"} eq "Exception"
!ll&&!rl&&r
000
$skipped_token and $skipped_token->{"type"} == 127
!ll&&!rl&&r
000
MC/DC0%0/3
$skipped_token and $skipped_token->{"type"} == 127 and $skipped_token->{"data"} eq "Exception"
$skipped_token $skipped_token->{"type"} == 127 $skipped_token->{"data"} eq "Exception"
Truth table0%0/4
A and B and C
A= $skipped_tokenB= $skipped_token->{"type"} == 127C= $skipped_token->{"data"} eq "Exception"
ABCresult
0XX0
10X0
1100
1111
88 0 ▶ for ($i += 3; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
89 0 my $token_type = $token->{type};
90 0 ▶ if ($token_type == REG_LIST) {
Branch: 4 branches
BranchTrueFalseTotal
if ($token_type == 147) { } 0 0 0
elsif ($token_type == 107) { } 0 0 0
elsif ($token_type == 172 || $token_type == 173 and $token->{'data'} eq 'open') { } 0 0 0
elsif ($token->{'kind'} == 21) { } 0 0 0
91 0 ▶ for ($i += 2; 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 0 ▶ if ($token_type == REG_EXP && $token->{data} eq 'open') {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 187 and $token->{'data'} eq 'open') { } 0 0 0
elsif ($token_type == 151) { } 0 0 0
Condition0%0/3
$token_type == 187 and $token->{"data"} eq "open"
!ll&&!rl&&r
000
MC/DC0%0/2
$token_type == 187 and $token->{"data"} eq "open"
$token_type == 187 $token->{"data"} eq "open"
Truth table0%0/3
A and B
A= $token_type == 187B= $token->{"data"} eq "open"
ABresult
0X0
100
111
94 0 return [];
95 }
96 elsif ($token_type == REG_DELIM) {
97 0 last;
98 }
99 }
100 }
101 elsif ($token_type == LEFT_PAREN) {
102 0 my $left_paren_num = 1;
103 0 ▶ for ($i++; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
104 0 my $token_type = $token->{type};
105 0 ▶ if ($token_type == LEFT_PAREN) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 107) { } 0 0 0
elsif ($token_type == 172 || $token_type == 173 and $token->{'data'} eq 'open') { } 0 0 0
106 0 $left_paren_num++;
107 }
108 ▶ elsif (($token_type == STRING || $token_type == RAW_STRING) && $token->{data} eq 'open') {
Condition0%0/6
$token_type == 172 || $token_type == 173 and $token->{"data"} eq "open"
!ll&&!rl&&r
000
$token_type == 172 or $token_type == 173
l!l&&r!l&&!r
000
MC/DC0%0/3
$token_type == 172 || $token_type == 173 and $token->{"data"} eq "open"
$token_type == 172 $token_type == 173 $token->{"data"} eq "open"
Truth table0%0/5
A or B and C
A= $token_type == 172B= $token_type == 173C= $token->{"data"} eq "open"
ABCresult
00X0
1X00
0100
1X11
0111
109 0 return [];
110 }
111 else {
112 0 ▶ last if --$left_paren_num <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if --$left_paren_num <= 0 0 0 0
113 }
114 }
115 }
116 ▶ elsif (($token_type == STRING || $token_type == RAW_STRING) && $token->{data} eq 'open') {
Condition0%0/6
$token_type == 172 || $token_type == 173 and $token->{"data"} eq "open"
!ll&&!rl&&r
000
$token_type == 172 or $token_type == 173
l!l&&r!l&&!r
000
MC/DC0%0/3
$token_type == 172 || $token_type == 173 and $token->{"data"} eq "open"
$token_type == 172 $token_type == 173 $token->{"data"} eq "open"
Truth table0%0/5
A or B and C
A= $token_type == 172B= $token_type == 173C= $token->{"data"} eq "open"
ABCresult
00X0
1X00
0100
1X11
0111
117 0 last;
118 }
119 elsif ($token->{kind} == KIND_STMT_END) {
120 0 last;
121 }
122 }
123 }
124  
125 0 next;
126 }
127  
128 0 ▶ if ($token_kind == KIND_STMT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_kind == 17) 0 0 0
129 0 $is_in_statement_context = 1;
130  
131 0 ▶ if ($tokens->[$i+1]->{type} == LEFT_PAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$tokens[$i + 1]{"type"} == 107) 0 0 0
132 0 $i++;
133 0 my $left_paren_num = 1;
134 0 ▶ for ($i++; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
135 0 my $token_type = $token->{type};
136 0 ▶ if ($token_type == LEFT_PAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 107) { } 0 0 0
137 0 $left_paren_num++;
138 }
139 else {
140 0 ▶ last if --$left_paren_num <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if --$left_paren_num <= 0 0 0 0
141 }
142 }
143 }
144 0 next;
145 }
146  
147 0 ▶ if ($token_type == BUILTIN_FUNC) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 70) 0 0 0
148 0 ▶ if ($token_data eq 'open') {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_data eq 'open') { } 0 0 0
elsif ($token_data eq 'no') { } 0 0 0
149 0 ▶ if (!$is_in_assign_context && !$is_in_statement_context) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($is_in_assign_context or $is_in_statement_context) 0 0 0
Condition0%0/3
$is_in_assign_context or $is_in_statement_context
l!l&&r!l&&!r
000
MC/DC0%0/2
$is_in_assign_context or $is_in_statement_context
$is_in_assign_context $is_in_statement_context
Truth table0%0/3
A or B
A= $is_in_assign_contextB= $is_in_statement_context
ABresult
1X1
011
000
150 0 $is_called_open_in_void = 1;
151 }
152 }
153 elsif ($token_data eq 'no') {
154 0 my $next_token = $tokens->[++$i];
155 0 ▶ if ($next_token->{type} == KEY && $next_token->{data} eq 'autodie') {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_token->{"type"} == 122 and $next_token->{"data"} eq "autodie") 0 0 0
Condition0%0/3
$next_token->{"type"} == 122 and $next_token->{"data"} eq "autodie"
!ll&&!rl&&r
000
MC/DC0%0/2
$next_token->{"type"} == 122 and $next_token->{"data"} eq "autodie"
$next_token->{"type"} == 122 $next_token->{"data"} eq "autodie"
Truth table0%0/3
A and B
A= $next_token->{"type"} == 122B= $next_token->{"data"} eq "autodie"
ABresult
0X0
100
111
156 0 $is_enabled_autodie = 0;
157 }
158 }
159 0 next;
160 }
161  
162 0 ▶ if ($token_kind == KIND_OP) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_kind == 1) 0 0 0
163 0 $is_called_open_in_void = 0;
164 0 next;
165 }
166  
167 0 ▶ if ($token_kind == KIND_STMT_END) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_kind == 21) 0 0 0
168 0 ▶ next if $is_enabled_autodie;
Branch: 1 branch
BranchTrueFalseTotal
if $is_enabled_autodie 0 0 0
169  
170 0 ▶ if ($is_called_open_in_void) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_called_open_in_void) 0 0 0
171 push @violations, {
172 filename => $file,
173 line => $token->{line},
174 0 description => DESC,
175 explanation => EXPL,
176 policy => __PACKAGE__,
177 };
178 }
179  
180 0 $is_in_assign_context = 0;
181 0 $is_in_statement_context = 0;
182 0 $is_called_open_in_void = 0;
183 0 next;
184 }
185  
186 }
187  
188 0 return \@violations;
189 }
190  
191 2 1;
192  
« Perl/Lint/Policy/InputOutput/RequireBriefOpen.pm ↑ Summary Perl/Lint/Policy/ErrorHandling/RequireCarping.pm »