Perl/Lint/Policy/BuiltinFunctions/ProhibitReverseSortBlock.pm

filter: Statementstmt 58.9% 23 / 39 Branchbran 12.5% 3 / 24 Conditioncond 11.1% 2 / 18 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 34.6% 34 / 98 CC 19 SCAR 51.4
CC
19
Cov
35%
evaluate
214.7
BEGIN
1.0
BEGIN
1.0
CRAP 170.2
« Perl/Lint/Policy/BuiltinFunctions/ProhibitUselessTopic.pm ↑ Summary Perl/Lint/Policy/RegularExpressions/ProhibitEnumeratedClasses.pm »
1 package Perl::Lint::Policy::BuiltinFunctions::ProhibitReverseSortBlock;
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 parent "Perl::Lint::Policy";
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 DESC => 'Forbid $b before $a in sort blocks',
9 EXPL => [152],
10 3 };
11  
12 2 ▶sub evaluate {
Subroutine evaluate: called CC=19 SCAR=53.7
Pod undocumented
13 2 my ($class, $file, $tokens, $src, $args) = @_;
14  
15 2 my @violations;
16 2 ▶ for (my $i = 0; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 51 2 53
17 51 my $token_type = $token->{type};
18 51 my $token_data = $token->{data};
19  
20 51 ▶ if ($token_type == BUILTIN_FUNC && $token_data eq 'sort') {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 70 and $token_data eq "sort") 0 51 51
Condition66%2/3
$token_type == 70 and $token_data eq "sort"
!ll&&!rl&&r
5010
MC/DC0%0/2
$token_type == 70 and $token_data eq "sort"
$token_type == 70 $token_data eq "sort"
Truth table66%2/3
A and B
A= $token_type == 70B= $token_data eq "sort"
ABresult
0X0
100
111
21 0 $token = $tokens->[++$i];
22 0 ▶ if ($token->{type} == LEFT_PAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->{"type"} == 107) 0 0 0
23 0 $token = $tokens->[++$i];
24 }
25  
26 0 ▶ if ($token->{type} == LEFT_BRACE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->{"type"} == 109) 0 0 0
27 0 my $left_brace_num = 1;
28 0 my $is_b_at_before_comparator = 0;
29 0 ▶ for ($i++; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
30 0 $token_type = $token->{type};
31 0 $token_data = $token->{data};
32 0 ▶ if ($token_type == COMPARE || $token_type == STRING_COMPARE) {
Branch: 5 branches
BranchTrueFalseTotal
if ($token_type == 33 or $token_type == 44) { } 0 0 0
elsif ($token_type == 109) { } 0 0 0
elsif ($token_type == 110) { } 0 0 0
elsif ($token_type == 166 and $token_data eq '$b') { } 0 0 0
elsif ($token_type == 53 or $token_type == 52 or $token_type == 14 or $token_type == 16) { } 0 0 0
Condition0%0/3
$token_type == 33 or $token_type == 44
l!l&&r!l&&!r
000
MC/DC0%0/2
$token_type == 33 or $token_type == 44
$token_type == 33 $token_type == 44
Truth table0%0/3
A or B
A= $token_type == 33B= $token_type == 44
ABresult
1X1
011
000
33 0 ▶ if ($is_b_at_before_comparator) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_b_at_before_comparator) 0 0 0
34 push @violations, {
35 filename => $file,
36 line => $token->{line},
37 0 description => DESC,
38 explanation => EXPL,
39 policy => __PACKAGE__,
40 };
41 }
42 }
43 elsif ($token_type == LEFT_BRACE) {
44 0 $left_brace_num++;
45 }
46 elsif ($token_type == RIGHT_BRACE) {
47 0 ▶ last if --$left_brace_num <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if --$left_brace_num <= 0 0 0 0
48 }
49 ▶ elsif ($token_type == VAR && $token_data eq '$b') {
Condition0%0/3
$token_type == 166 and $token_data eq "\$b"
!ll&&!rl&&r
000
MC/DC0%0/2
$token_type == 166 and $token_data eq "\$b"
$token_type == 166 $token_data eq "\$b"
Truth table0%0/3
A and B
A= $token_type == 166B= $token_data eq "\$b"
ABresult
0X0
100
111
50 0 $is_b_at_before_comparator = 1;
51 }
52 ▶ elsif ( # XXX enough?
Condition0%0/9
$token_type == 53 or $token_type == 52 or $token_type == 14 or $token_type == 16
l!l&&r!l&&!r
000
$token_type == 53 or $token_type == 52 or $token_type == 14
l!l&&r!l&&!r
000
$token_type == 53 or $token_type == 52
l!l&&r!l&&!r
000
MC/DC0%0/4
$token_type == 53 or $token_type == 52 or $token_type == 14 or $token_type == 16
$token_type == 53 $token_type == 52 $token_type == 14 $token_type == 16
Truth table0%0/5
A or B or C or D
A= $token_type == 53B= $token_type == 52C= $token_type == 14D= $token_type == 16
ABCDresult
1XXX1
01XX1
001X1
00011
00000
53 $token_type == OR ||
54 $token_type == AND ||
55 $token_type == ALPHABET_OR ||
56 $token_type == ALPHABET_AND
57 ) {
58 0 $is_b_at_before_comparator = 0;
59 }
60 }
61 }
62 }
63 }
64  
65 2 return \@violations;
66 }
67  
68 3 1;
69  
« Perl/Lint/Policy/BuiltinFunctions/ProhibitUselessTopic.pm ↑ Summary Perl/Lint/Policy/RegularExpressions/ProhibitEnumeratedClasses.pm »