Perl/Lint/Policy/ControlStructures/ProhibitNegativeExpressionsInUnlessAndUntilConditions.pm

filter: Statementstmt 42.5% 17 / 40 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 1 totaltotal 28.9% 22 / 76 CC 14 SCAR 50.4
CC
14
Cov
25%
evaluate
210.0
BEGIN
1.0
BEGIN
1.0
CRAP 155.0
« Perl/Lint/Policy/TestingAndDebugging/RequireUseWarnings.pm ↑ Summary Perl/Lint/Policy/InputOutput/ProhibitOneArgSelect.pm »
1 package Perl::Lint::Policy::ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions;
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 => 'Found "%s" in condition for an "%s"',
9 EXPL => [99],
10 2 };
11  
12 2 my %invalid_op_types = (
13 &NOT => '!',
14 &ALPHABET_NOT => 'not',
15 &STRING_NOT_EQUAL => 'ne',
16 &NOT_EQUAL => '!=',
17 &LESS => '<',
18 &LESS_EQUAL => '<=',
19 &GREATER => '>',
20 &GREATER_EQUAL => '>=',
21 &COMPARE => '<=>',
22 &STRING_LESS => 'lt',
23 &STRING_GREATER => 'gt',
24 &STRING_LESS_EQUAL => 'le',
25 &STRING_GREATER_EQUAL => 'ge',
26 &STRING_COMPARE => 'cmp',
27 &REG_NOT => '!~',
28 &STRING_NOT_EQUAL => 'ne',
29 &NOT_EQUAL => '!=',
30 );
31  
32 0 ▶sub evaluate {
Subroutine evaluate: not called CC=14 SCAR=53.5
Pod undocumented
33 0 my ($class, $file, $tokens, $src, $args) = @_;
34  
35 0 my @violations;
36 0 ▶ for (my $i = 0, my $token_type; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
37 0 $token_type = $token->{type};
38 0 ▶ if ($token_type == UNLESS_STATEMENT || $token_type == UNTIL_STATEMENT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 99 or $token_type == 100) 0 0 0
Condition0%0/3
$token_type == 99 or $token_type == 100
l!l&&r!l&&!r
000
MC/DC0%0/2
$token_type == 99 or $token_type == 100
$token_type == 99 $token_type == 100
Truth table0%0/3
A or B
A= $token_type == 99B= $token_type == 100
ABresult
1X1
011
000
39 0 my $control_structure = $token->{data};
40  
41 0 ▶ $token = $tokens->[++$i] or last;
Branch: 1 branch
BranchTrueFalseTotal
$token = $$tokens[++$i] or last 0 0 0
42 0 ▶ if ($token->{type} != LEFT_PAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->{"type"} != 107) 0 0 0
43 0 ▶ for (; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
44 0 $token_type = $token->{type};
45 0 ▶ if ($token_type == SEMI_COLON) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 106) { } 0 0 0
elsif ($invalid_op_types{$token_type}) { } 0 0 0
46 0 last;
47 }
48 elsif ($invalid_op_types{$token_type}) {
49 push @violations, {
50 filename => $file,
51 line => $token->{line},
52 0 description => sprintf(DESC, $invalid_op_types{$token_type}, $control_structure),
53 explanation => EXPL,
54 policy => __PACKAGE__,
55 };
56 }
57 }
58  
59 0 next;
60 }
61  
62 0 my $lpnum = 1;
63 0 ▶ for ($i++; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
64 0 $token_type = $token->{type};
65  
66 0 ▶ if ($token_type == LEFT_PAREN) {
Branch: 3 branches
BranchTrueFalseTotal
if ($token_type == 107) { } 0 0 0
elsif ($token_type == 108) { } 0 0 0
elsif ($invalid_op_types{$token_type}) { } 0 0 0
67 0 $lpnum++;
68 }
69 elsif ($token_type == RIGHT_PAREN) {
70 0 ▶ last if --$lpnum <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if --$lpnum <= 0 0 0 0
71 }
72 elsif ($invalid_op_types{$token_type}) {
73 push @violations, {
74 filename => $file,
75 line => $token->{line},
76 0 description => sprintf(DESC, $invalid_op_types{$token_type}, $control_structure),
77 explanation => EXPL,
78 policy => __PACKAGE__,
79 };
80 0 last;
81 }
82 }
83 }
84 }
85  
86 0 return \@violations;
87 }
88  
89 2 1;
90  
« Perl/Lint/Policy/TestingAndDebugging/RequireUseWarnings.pm ↑ Summary Perl/Lint/Policy/InputOutput/ProhibitOneArgSelect.pm »