Perl/Lint/Policy/InputOutput/RequireCheckedClose.pm

filter: Statementstmt 54.5% 60 / 110 Branchbran 26.6% 25 / 94 Conditioncond 2.0% 1 / 48 MC/DCmcdc 0.0% 0 / 27 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 32.4% 93 / 287 CC 64 SCAR 72.5
CC
64
Cov
34%
evaluate
1545.2
BEGIN
1.0
BEGIN
1.0
CRAP 1412.8
« Perl/Lint/Policy/TestingAndDebugging/RequireTestLabels.pm ↑ Summary Perl/Lint/Policy/Subroutines/RequireArgUnpacking.pm »
1 package Perl::Lint::Policy::InputOutput::RequireCheckedClose;
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 => 'Return value of "close" ignored',
10 EXPL => 'Check the return value of "close" for success',
11 3 };
12  
13 2 ▶sub evaluate {
Subroutine evaluate: called CC=64 SCAR=73.4
Pod undocumented
14 2 my ($class, $file, $tokens, $src, $args) = @_;
15  
16 2 my $is_in_assign_context = 0;
17 2 my $is_in_statement_context = 0;
18 2 my $is_called_close_in_void = 0;
19 2 my $is_enabled_autodie = 0;
20 2 my @violations;
21 2 ▶ for (my $i = 0; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 49 2 51
22 49 my $token_type = $token->{type};
23 49 my $token_kind = $token->{kind};
24 49 my $token_data = $token->{data};
25  
26 49 ▶ if ($token_type == ASSIGN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 65) 1 48 49
27 1 $is_in_assign_context = 1;
28 1 next;
29 }
30  
31 48 ▶ if ($token_type == USED_NAME) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 94) 8 40 48
32 8 ▶ if ($token_data eq 'Fatal') {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_data eq 'Fatal') { } 0 8 8
elsif ($token_data eq 'autodie') { } 0 8 8
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 'close') { } 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 'close') {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 187 and $token->{'data'} eq 'close') { } 0 0 0
elsif ($token_type == 151) { } 0 0 0
Condition0%0/3
$token_type == 187 and $token->{"data"} eq "close"
!ll&&!rl&&r
000
MC/DC0%0/2
$token_type == 187 and $token->{"data"} eq "close"
$token_type == 187 $token->{"data"} eq "close"
Truth table0%0/3
A and B
A= $token_type == 187B= $token->{"data"} eq "close"
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 'close') { } 0 0 0
51 0 $left_paren_num++;
52 }
53 ▶ elsif (($token_type == STRING || $token_type == RAW_STRING) && $token->{data} eq 'close') {
Condition0%0/6
$token_type == 172 || $token_type == 173 and $token->{"data"} eq "close"
!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 "close"
$token_type == 172 $token_type == 173 $token->{"data"} eq "close"
Truth table0%0/5
A or B and C
A= $token_type == 172B= $token_type == 173C= $token->{"data"} eq "close"
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 'close') {
Condition0%0/6
$next_token_type == 172 || $next_token_type == 173 and $next_token->{"data"} eq "close"
!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 "close"
$next_token_type == 172 $next_token_type == 173 $next_token->{"data"} eq "close"
Truth table0%0/5
A or B and C
A= $next_token_type == 172B= $next_token_type == 173C= $next_token->{"data"} eq "close"
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 8 next;
83 }
84  
85 40 ▶ if ($token_type == NAMESPACE && $token_data eq 'Fatal') {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 127 and $token_data eq "Fatal") 0 40 40
Condition33%1/3
$token_type == 127 and $token_data eq "Fatal"
!ll&&!rl&&r
4000
MC/DC0%0/2
$token_type == 127 and $token_data eq "Fatal"
$token_type == 127 $token_data eq "Fatal"
Truth table33%1/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 'close') { } 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 'close') {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 187 and $token->{'data'} eq 'close') { } 0 0 0
elsif ($token_type == 151) { } 0 0 0
Condition0%0/3
$token_type == 187 and $token->{"data"} eq "close"
!ll&&!rl&&r
000
MC/DC0%0/2
$token_type == 187 and $token->{"data"} eq "close"
$token_type == 187 $token->{"data"} eq "close"
Truth table0%0/3
A and B
A= $token_type == 187B= $token->{"data"} eq "close"
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 'close') { } 0 0 0
106 0 $left_paren_num++;
107 }
108 ▶ elsif (($token_type == STRING || $token_type == RAW_STRING) && $token->{data} eq 'close') {
Condition0%0/6
$token_type == 172 || $token_type == 173 and $token->{"data"} eq "close"
!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 "close"
$token_type == 172 $token_type == 173 $token->{"data"} eq "close"
Truth table0%0/5
A or B and C
A= $token_type == 172B= $token_type == 173C= $token->{"data"} eq "close"
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 'close') {
Condition0%0/6
$token_type == 172 || $token_type == 173 and $token->{"data"} eq "close"
!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 "close"
$token_type == 172 $token_type == 173 $token->{"data"} eq "close"
Truth table0%0/5
A or B and C
A= $token_type == 172B= $token_type == 173C= $token->{"data"} eq "close"
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 40 ▶ if ($token_kind == KIND_STMT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_kind == 17) 1 39 40
129 1 $is_in_statement_context = 1;
130  
131 1 ▶ if ($tokens->[$i+1]->{type} == LEFT_PAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$tokens[$i + 1]{"type"} == 107) 1 0 1
132 1 $i++;
133 1 my $left_paren_num = 1;
134 1 ▶ for ($i++; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 1 0 1
135 1 my $token_type = $token->{type};
136 1 ▶ if ($token_type == LEFT_PAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 107) { } 0 1 1
137 0 $left_paren_num++;
138 }
139 else {
140 1 ▶ last if --$left_paren_num <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if --$left_paren_num <= 0 1 0 1
141 }
142 }
143 }
144 1 next;
145 }
146  
147 39 ▶ if ($token_type == BUILTIN_FUNC) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 70) 1 38 39
148 1 ▶ if ($token_data eq 'close') {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_data eq 'close') { } 0 1 1
elsif ($token_data eq 'no') { } 0 1 1
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_close_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 1 next;
160 }
161  
162 38 ▶ if ($token_kind == KIND_OP) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_kind == 1) 2 36 38
163 2 $is_called_close_in_void = 0;
164 2 next;
165 }
166  
167 36 ▶ if ($token_kind == KIND_STMT_END) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_kind == 21) 11 25 36
168 11 ▶ next if $is_enabled_autodie;
Branch: 1 branch
BranchTrueFalseTotal
if $is_enabled_autodie 0 11 11
169  
170 11 ▶ if ($is_called_close_in_void) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_called_close_in_void) 0 11 11
171 push @violations, {
172 filename => $file,
173 line => $token->{line},
174 0 description => DESC,
175 explanation => EXPL,
176 policy => __PACKAGE__,
177 };
178 }
179  
180 11 $is_in_assign_context = 0;
181 11 $is_in_statement_context = 0;
182 11 $is_called_close_in_void = 0;
183 11 next;
184 }
185  
186 }
187  
188 2 return \@violations;
189 }
190  
191 3 1;
192  
« Perl/Lint/Policy/TestingAndDebugging/RequireTestLabels.pm ↑ Summary Perl/Lint/Policy/Subroutines/RequireArgUnpacking.pm »