Perl/Lint/Policy/Subroutines/ProhibitReturnSort.pm

filter: Statementstmt 33.3% 16 / 48 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 1 totaltotal 18.2% 21 / 115 CC 23 SCAR 61.2
CC
23
Cov
16%
evaluate
552.0
BEGIN
1.0
BEGIN
1.0
CRAP 453.6
« Perl/Lint/Policy/Variables/ProhibitReusedNames.pm ↑ Summary Perl/Lint/Policy/TestingAndDebugging/ProhibitProlongedStrictureOverride.pm »
1 package Perl::Lint::Policy::Subroutines::ProhibitReturnSort;
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 parent "Perl::Lint::Policy";
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 DESC => '"return" statement followed by "sort"',
9 EXPL => 'Behavior is undefined if called in scalar context',
10 2 };
11  
12 0 ▶sub evaluate {
Subroutine evaluate: not called CC=23 SCAR=63.1
Pod undocumented
13 0 my ($class, $file, $tokens, $args) = @_;
14  
15 0 my @violations;
16 0 ▶ for (my $i = 0; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
17 0 my $token_type = $token->{type};
18  
19 0 ▶ if ($token_type == RETURN) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 0) { } 0 0 0
elsif ($token_type == 96) { } 0 0 0
20 0 my $next_token = $tokens->[$i+1];
21 0 ▶ if ($next_token->{type} == BUILTIN_FUNC && $next_token->{data} eq 'sort') {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_token->{"type"} == 70 and $next_token->{"data"} eq "sort") 0 0 0
Condition0%0/3
$next_token->{"type"} == 70 and $next_token->{"data"} eq "sort"
!ll&&!rl&&r
000
MC/DC0%0/2
$next_token->{"type"} == 70 and $next_token->{"data"} eq "sort"
$next_token->{"type"} == 70 $next_token->{"data"} eq "sort"
Truth table0%0/3
A and B
A= $next_token->{"type"} == 70B= $next_token->{"data"} eq "sort"
ABresult
0X0
100
111
22 0 my $is_in_postposition_if = 0;
23 0 my $is_wantarray = 0;
24 0 ▶ for ($i++; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
25 0 my $token_type = $token->{type};
26 0 ▶ if ($token_type == SEMI_COLON) {
Branch: 3 branches
BranchTrueFalseTotal
if ($token_type == 106) { } 0 0 0
elsif ($token_type == 96) { } 0 0 0
elsif ($token_type == 70 and $token->{'data'} eq 'wantarray' and $is_in_postposition_if) { } 0 0 0
27 0 ▶ if (!$is_wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($is_wantarray) 0 0 0
28 push @violations, {
29 filename => $file,
30 line => $token->{line},
31 0 description => DESC,
32 explanation => EXPL,
33 policy => __PACKAGE__,
34 };
35 }
36 0 last;
37 }
38 elsif ($token_type == IF_STATEMENT) {
39 0 $is_in_postposition_if = 1;
40 }
41 ▶ elsif ($token_type == BUILTIN_FUNC && $token->{data} eq 'wantarray' && $is_in_postposition_if) {
Condition0%0/6
$token_type == 70 and $token->{"data"} eq "wantarray" and $is_in_postposition_if
!ll&&!rl&&r
000
$token_type == 70 and $token->{"data"} eq "wantarray"
!ll&&!rl&&r
000
MC/DC0%0/3
$token_type == 70 and $token->{"data"} eq "wantarray" and $is_in_postposition_if
$token_type == 70 $token->{"data"} eq "wantarray" $is_in_postposition_if
Truth table0%0/4
A and B and C
A= $token_type == 70B= $token->{"data"} eq "wantarray"C= $is_in_postposition_if
ABCresult
0XX0
10X0
1100
1111
42 0 $is_wantarray = 1;
43 }
44 }
45 0 next;
46 }
47 }
48 elsif ($token_type == IF_STATEMENT) {
49 0 my $left_brace_num = 0;
50 0 my $is_wantarray = 0;
51 0 ▶ for ($i++; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
52 0 my $token_type = $token->{type};
53 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 == 70 and $token->{'data'} eq 'wantarray') { } 0 0 0
elsif (not $is_wantarray) { } 0 0 0
54 0 $left_brace_num++;
55 }
56 elsif ($token_type == RIGHT_BRACE) {
57 0 $left_brace_num--;
58 0 ▶ last if ($left_brace_num <= 0);
Branch: 1 branch
BranchTrueFalseTotal
if $left_brace_num <= 0 0 0 0
59 }
60 ▶ elsif ($token_type == BUILTIN_FUNC && $token->{data} eq 'wantarray') {
Condition0%0/3
$token_type == 70 and $token->{"data"} eq "wantarray"
!ll&&!rl&&r
000
MC/DC0%0/2
$token_type == 70 and $token->{"data"} eq "wantarray"
$token_type == 70 $token->{"data"} eq "wantarray"
Truth table0%0/3
A and B
A= $token_type == 70B= $token->{"data"} eq "wantarray"
ABresult
0X0
100
111
61 0 $is_wantarray = 1;
62 }
63 elsif (!$is_wantarray) {
64 0 my $next_token = $tokens->[$i+1];
65 0 ▶ if ($next_token && $next_token->{type} == BUILTIN_FUNC && $next_token->{data} eq 'sort') {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_token and $next_token->{"type"} == 70 and $next_token->{"data"} eq "sort") 0 0 0
Condition0%0/6
$next_token and $next_token->{"type"} == 70 and $next_token->{"data"} eq "sort"
!ll&&!rl&&r
000
$next_token and $next_token->{"type"} == 70
!ll&&!rl&&r
000
MC/DC0%0/3
$next_token and $next_token->{"type"} == 70 and $next_token->{"data"} eq "sort"
$next_token $next_token->{"type"} == 70 $next_token->{"data"} eq "sort"
Truth table0%0/4
A and B and C
A= $next_tokenB= $next_token->{"type"} == 70C= $next_token->{"data"} eq "sort"
ABCresult
0XX0
10X0
1100
1111
66 push @violations, {
67 filename => $file,
68 line => $token->{line},
69 0 description => DESC,
70 explanation => EXPL,
71 policy => __PACKAGE__,
72 };
73 0 next;
74 }
75 }
76 }
77 }
78 }
79  
80 0 return \@violations;
81 }
82  
83 2 1;
84  
« Perl/Lint/Policy/Variables/ProhibitReusedNames.pm ↑ Summary Perl/Lint/Policy/TestingAndDebugging/ProhibitProlongedStrictureOverride.pm »