Perl/Lint/Policy/Subroutines/RequireFinalReturn.pm

filter: Statementstmt 21.5% 22 / 102 Branchbran 0.0% 0 / 72 Conditioncond 0.0% 0 / 56 MC/DCmcdc 0.0% 0 / 30 Subroutinesub 70.0% 7 / 10 Podpod 0.0% 0 / 1 totaltotal 10.7% 29 / 271 CC 57 SCAR 79.6
CC
57
Cov
10%
evaluate
3306.0
__ANON__
2.0
__ANON__
2.0
CRAP 2855.3
« Perl/Lint/Policy/ErrorHandling/RequireCarping.pm ↑ Summary Perl/Lint/Policy/Subroutines/ProhibitUnusedPrivateSubroutines.pm »
1 package Perl::Lint::Policy::Subroutines::RequireFinalReturn;
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 List::Util qw/any/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use parent "Perl::Lint::Policy";
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 DESC => 'The additional subroutines to treat as terminal',
11 EXPL => [197],
12 2 };
13  
14 0 ▶sub evaluate {
Subroutine evaluate: not called CC=57 SCAR=81.0
Pod undocumented
15 0 my ($class, $file, $tokens, $src, $args) = @_;
16  
17 0 ▶ my @terminal_funcs = split(/ /, $args->{require_final_return}->{terminal_funcs} || '');
Condition0%0/2
$args->{'require_final_return'}{'terminal_funcs'} || ''
l!l
00
MC/DC0%0/1
$args->{'require_final_return'}{'terminal_funcs'} || ''
$args->{'require_final_return'}{'terminal_funcs'}
Truth table0%0/2
A
A= $args->{'require_final_return'}{'terminal_funcs'}
Aresult
11
00
18  
19 0 my @violations;
20 0 my $is_in_sub = 0;
21 0 my $left_brace_num = 0;
22 0 ▶ for (my $i = 0; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
23 0 my $token_type = $token->{type};
24 0 ▶ if ($token_type == FUNCTION_DECL) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 63) 0 0 0
25 0 ▶ for ($i++; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
26 0 $token_type = $token->{type};
27 0 ▶ if ($token_type == LEFT_BRACE) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 109) { } 0 0 0
elsif ($token_type == 106) { } 0 0 0
28 0 ▶ if ($tokens->[$i+1]->{type} == RIGHT_BRACE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$tokens[$i + 1]{"type"} == 110) 0 0 0
29 0 last;
30 }
31  
32 0 my $left_brace_num = 1;
33 0 my $is_returned = 0;
34 0 my $is_returned_in_cond = undef;
35 0 my %constant_loop;
36 0 ▶ for ($i++; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
37 0 $token_type = $token->{type};
38 0 my $token_data = $token->{data};
39  
40 0 ▶ if ($token_type == LEFT_BRACE) {
Branch: 8 branches
BranchTrueFalseTotal
if ($token_type == 109) { } 0 0 0
elsif ($token_type == 110) { } 0 0 0
elsif ($token_type == 96 or $token_type == 98 or $token_type == 97 or $token_type == 99) { } 0 0 0
elsif ($token_type == 133 or $token_type == 134 or $token_type == 132 or $token_type == 100) { } 0 0 0
elsif ($token_type == 0 or $token_type == 85) { } 0 0 0
elsif ($token_type == 70) { } 0 0 0
elsif ($token_type == 122) { } 0 0 0
elsif ($token_type == 127 and $token_data eq 'Carp') { } 0 0 0
41 0 $left_brace_num++;
42 }
43 elsif ($token_type == RIGHT_BRACE) {
44 0 delete $constant_loop{$left_brace_num};
45 0 ▶ if (--$left_brace_num <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (--$left_brace_num <= 0) 0 0 0
46 0 ▶ if (!$is_returned && !$is_returned_in_cond) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($is_returned or $is_returned_in_cond) 0 0 0
Condition0%0/3
$is_returned or $is_returned_in_cond
l!l&&r!l&&!r
000
MC/DC0%0/2
$is_returned or $is_returned_in_cond
$is_returned $is_returned_in_cond
Truth table0%0/3
A or B
A= $is_returnedB= $is_returned_in_cond
ABresult
1X1
011
000
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 (
Condition0%0/9
$token_type == 96 or $token_type == 98 or $token_type == 97 or $token_type == 99
l!l&&r!l&&!r
000
$token_type == 96 or $token_type == 98 or $token_type == 97
l!l&&r!l&&!r
000
$token_type == 96 or $token_type == 98
l!l&&r!l&&!r
000
MC/DC0%0/4
$token_type == 96 or $token_type == 98 or $token_type == 97 or $token_type == 99
$token_type == 96 $token_type == 98 $token_type == 97 $token_type == 99
Truth table0%0/5
A or B or C or D
A= $token_type == 96B= $token_type == 98C= $token_type == 97D= $token_type == 99
ABCDresult
1XXX1
01XX1
001X1
00011
00000
59 $token_type == IF_STATEMENT ||
60 $token_type == ELSIF_STATEMENT ||
61 $token_type == ELSE_STATEMENT ||
62 $token_type == UNLESS_STATEMENT
63 ) {
64 0 ▶ $is_returned_in_cond //= 1; # at once
Condition0%0/2
$is_returned_in_cond //= 1
l!l
00
MC/DC0%0/1
$is_returned_in_cond //= 1
$is_returned_in_cond
Truth table0%0/2
A
A= $is_returned_in_cond
Aresult
11
00
65  
66 0 my $left_brace_num = 0;
67 0 my $is_returned_in_cond_locally = 0;
68 0 ▶ for ($i++; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
69 0 $token_type = $token->{type};
70 0 $token_data = $token->{data};
71 0 ▶ if ($token_type == LEFT_BRACE) {
Branch: 4 branches
BranchTrueFalseTotal
if ($token_type == 109) { } 0 0 0
elsif ($token_type == 110) { } 0 0 0
elsif ($token_type == 0 or $token_type == 85) { } 0 0 0
elsif ($token_type == 122 and &any(sub { $_ eq $token_data; } , @terminal_funcs)) { } 0 0 0
72 0 $left_brace_num++;
73 }
74 elsif ($token_type == RIGHT_BRACE) {
75 0 ▶ if (!$is_returned_in_cond_locally) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($is_returned_in_cond_locally) 0 0 0
76 0 $is_returned_in_cond = 0;
77 }
78 0 last;
79 }
80 ▶ elsif ($token_type == RETURN || $token_type == GOTO) {
Condition0%0/3
$token_type == 0 or $token_type == 85
l!l&&r!l&&!r
000
MC/DC0%0/2
$token_type == 0 or $token_type == 85
$token_type == 0 $token_type == 85
Truth table0%0/3
A or B
A= $token_type == 0B= $token_type == 85
ABresult
1X1
011
000
81 0 $is_returned_in_cond_locally = 1;
82 }
83 0 ▶ elsif ($token_type == KEY && any {$_ eq $token_data} @terminal_funcs) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
$token_type == 122 and &any(sub { $_ eq $token_data; } , @terminal_funcs)
!ll&&!rl&&r
000
MC/DC0%0/2
$token_type == 122 and &any(sub { $_ eq $token_data; } , @terminal_funcs)
$token_type == 122 &any(sub { $_ eq $token_data; } , @terminal_funcs)
Truth table0%0/3
A and B
A= $token_type == 122B= &any(sub { $_ eq $token_data; } , @terminal_funcs)
ABresult
0X0
100
111
84 0 $is_returned_in_cond_locally = 1;
85 }
86 }
87 }
88 ▶ elsif (
Condition0%0/9
$token_type == 133 or $token_type == 134 or $token_type == 132 or $token_type == 100
l!l&&r!l&&!r
000
$token_type == 133 or $token_type == 134 or $token_type == 132
l!l&&r!l&&!r
000
$token_type == 133 or $token_type == 134
l!l&&r!l&&!r
000
MC/DC0%0/4
$token_type == 133 or $token_type == 134 or $token_type == 132 or $token_type == 100
$token_type == 133 $token_type == 134 $token_type == 132 $token_type == 100
Truth table0%0/5
A or B or C or D
A= $token_type == 133B= $token_type == 134C= $token_type == 132D= $token_type == 100
ABCDresult
1XXX1
01XX1
001X1
00011
00000
89 $token_type == FOR_STATEMENT ||
90 $token_type == FOREACH_STATEMENT ||
91 $token_type == WHILE_STATEMENT ||
92 $token_type == UNTIL_STATEMENT
93 ) {
94 0 $constant_loop{$left_brace_num+1} = 1;
95 }
96 ▶ elsif ($token_type == RETURN || $token_type == GOTO) {
Condition0%0/3
$token_type == 0 or $token_type == 85
l!l&&r!l&&!r
000
MC/DC0%0/2
$token_type == 0 or $token_type == 85
$token_type == 0 $token_type == 85
Truth table0%0/3
A or B
A= $token_type == 0B= $token_type == 85
ABresult
1X1
011
000
97 0 ▶ if ($constant_loop{$left_brace_num}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($constant_loop{$left_brace_num}) 0 0 0
98 0 next;
99 }
100  
101 0 $is_returned = 1;
102 }
103 elsif ($token_type == BUILTIN_FUNC) {
104 0 ▶ if ($constant_loop{$left_brace_num}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($constant_loop{$left_brace_num}) 0 0 0
105 0 next;
106 }
107  
108 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($token_data eq "die" or $token_data eq "exec" or $token_data eq "exit") 0 0 0
Condition0%0/6
$token_data eq "die" or $token_data eq "exec" or $token_data eq "exit"
l!l&&r!l&&!r
000
$token_data eq "die" or $token_data eq "exec"
l!l&&r!l&&!r
000
MC/DC0%0/3
$token_data eq "die" or $token_data eq "exec" or $token_data eq "exit"
$token_data eq "die" $token_data eq "exec" $token_data eq "exit"
Truth table0%0/4
A or B or C
A= $token_data eq "die"B= $token_data eq "exec"C= $token_data eq "exit"
ABCresult
1XX1
01X1
0011
0000
109 $token_data eq 'die' ||
110 $token_data eq 'exec' ||
111 $token_data eq 'exit'
112 ) {
113 0 my $next_token = $tokens->[$i+1];
114 0 ▶ if ($next_token->{kind} == KIND_STMT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_token->{"kind"} == 17) 0 0 0
115 0 $i++;
116 0 next;
117 }
118 0 $is_returned = 1;
119 }
120 }
121 elsif ($token_type == KEY) {
122 0 ▶ if ($constant_loop{$left_brace_num}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($constant_loop{$left_brace_num}) 0 0 0
123 0 next;
124 }
125  
126 0 ▶ if (
Branch: 2 branches
BranchTrueFalseTotal
if ($token_data eq 'croak' or $token_data eq 'confess' or &any(sub { $_ eq $token_data; } , @terminal_funcs)) { } 0 0 0
elsif ($token_data eq 'throw') { } 0 0 0
Condition0%0/6
$token_data eq "croak" or $token_data eq "confess" or &any(sub { $_ eq $token_data; } , @terminal_funcs)
l!l&&r!l&&!r
000
$token_data eq "croak" or $token_data eq "confess"
l!l&&r!l&&!r
000
MC/DC0%0/3
$token_data eq "croak" or $token_data eq "confess" or &any(sub { $_ eq $token_data; } , @terminal_funcs)
$token_data eq "croak" $token_data eq "confess" &any(sub { $_ eq $token_data; } , @terminal_funcs)
Truth table0%0/4
A or B or C
A= $token_data eq "croak"B= $token_data eq "confess"C= &any(sub { $_ eq $token_data; } , @terminal_funcs)
ABCresult
1XX1
01X1
0011
0000
127 $token_data eq 'croak' ||
128 $token_data eq 'confess' ||
129 0 ▶ any {$_ eq $token_data} @terminal_funcs
Subroutine __ANON__: not called CC=1 SCAR=6.9
130 ) {
131 0 my $next_token = $tokens->[$i+1];
132 0 ▶ if (($next_token->{kind} || -1) == KIND_STMT) {
Branch: 1 branch
BranchTrueFalseTotal
if (($next_token->{'kind'} || -1) == 17) { } 0 0 0
Condition0%0/2
$next_token->{'kind'} || -1
l!l
00
MC/DC0%0/1
$next_token->{'kind'} || -1
$next_token->{'kind'}
Truth table0%0/2
A
A= $next_token->{'kind'}
Aresult
11
00
133 0 $i++;
134 0 next;
135 }
136 else {
137 0 my $next_token = $tokens->[$i+2];
138 0 ▶ if (($next_token->{kind} || -1) == KIND_STMT) {
Branch: 1 branch
BranchTrueFalseTotal
if (($next_token->{"kind"} || -1) == 17) 0 0 0
Condition0%0/2
$next_token->{'kind'} || -1
l!l
00
MC/DC0%0/1
$next_token->{'kind'} || -1
$next_token->{'kind'}
Truth table0%0/2
A
A= $next_token->{'kind'}
Aresult
11
00
139 0 $i += 2;
140 0 next;
141 }
142 }
143 0 $is_returned = 1;
144 }
145 elsif ($token_data eq 'throw') {
146 0 my $target_token = $tokens->[$i+2];
147 0 ▶ if ($target_token->{kind} == KIND_STMT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target_token->{"kind"} == 17) 0 0 0
148 0 $i += 2;
149 0 next;
150 }
151 0 $is_returned = 1;
152 }
153 }
154 ▶ elsif ($token_type == NAMESPACE && $token_data eq 'Carp') {
Condition0%0/3
$token_type == 127 and $token_data eq "Carp"
!ll&&!rl&&r
000
MC/DC0%0/2
$token_type == 127 and $token_data eq "Carp"
$token_type == 127 $token_data eq "Carp"
Truth table0%0/3
A and B
A= $token_type == 127B= $token_data eq "Carp"
ABresult
0X0
100
111
155 0 ▶ if ($constant_loop{$left_brace_num}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($constant_loop{$left_brace_num}) 0 0 0
156 0 next;
157 }
158  
159 0 my $target_token = $tokens->[$i+2];
160 0 ▶ if ($target_token->{type} == NAMESPACE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target_token->{"type"} == 127) 0 0 0
161 0 my $target_token_data = $target_token->{data};
162 0 ▶ if ($target_token_data eq 'croak' || $target_token_data eq 'confess') {
Branch: 1 branch
BranchTrueFalseTotal
if ($target_token_data eq "croak" or $target_token_data eq "confess") 0 0 0
Condition0%0/3
$target_token_data eq "croak" or $target_token_data eq "confess"
l!l&&r!l&&!r
000
MC/DC0%0/2
$target_token_data eq "croak" or $target_token_data eq "confess"
$target_token_data eq "croak" $target_token_data eq "confess"
Truth table0%0/3
A or B
A= $target_token_data eq "croak"B= $target_token_data eq "confess"
ABresult
1X1
011
000
163 0 $is_returned = 1;
164 }
165 }
166 }
167 }
168 }
169 elsif ($token_type == SEMI_COLON) {
170 0 last;
171 }
172 }
173 }
174 }
175  
176 0 return \@violations;
177 }
178  
179 2 1;
180  
« Perl/Lint/Policy/ErrorHandling/RequireCarping.pm ↑ Summary Perl/Lint/Policy/Subroutines/ProhibitUnusedPrivateSubroutines.pm »