Perl/Lint/Policy/InputOutput/RequireBracedFileHandleWithPrint.pm

filter: Statementstmt 80.9% 34 / 42 Branchbran 64.2% 9 / 14 Conditioncond 16.6% 5 / 30 MC/DCmcdc 7.6% 1 / 13 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 52.3% 56 / 107 CC 18 SCAR 40.6
CC
18
Cov
56%
evaluate
77.1
BEGIN
1.0
BEGIN
1.0
CRAP 58.1
« Perl/Lint/Policy/Subroutines/ProhibitNestedSubs.pm ↑ Summary Perl/Lint/Policy/ControlStructures/ProhibitPostfixControls.pm »
1 package Perl::Lint::Policy::InputOutput::RequireBracedFileHandleWithPrint;
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 => 'File handle for "print" or "printf" is not braced',
10 EXPL => [217],
11 3 };
12  
13 2 ▶sub evaluate {
Subroutine evaluate: called CC=18 SCAR=43.5
Pod undocumented
14 2 my ($class, $file, $tokens, $src, $args) = @_;
15  
16 2 my @violations;
17 2 ▶ for (my $i = 0; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 49 2 51
18 49 my $token_type = $token->{type};
19 49 my $token_data = $token->{data};
20  
21 49 ▶ if ($token_type == BUILTIN_FUNC && ($token_data eq 'print' || $token_data eq 'printf' || $token_data eq 'say')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 70 and $token_data eq "print" || $token_data eq "printf" || $token_data eq "say") 1 48 49
Condition44%4/9
$token_type == 70 and $token_data eq "print" || $token_data eq "printf" || $token_data eq "say"
!ll&&!rl&&r
4801
$token_data eq "print" or $token_data eq "printf" or $token_data eq "say"
l!l&&r!l&&!r
100
$token_data eq "print" or $token_data eq "printf"
l!l&&r!l&&!r
100
MC/DC25%1/4
$token_type == 70 and $token_data eq "print" || $token_data eq "printf" || $token_data eq "say"
$token_type == 70 $token_data eq "print" $token_data eq "printf" $token_data eq "say"
Truth table40%2/5
A and B or C or D
A= $token_type == 70B= $token_data eq "print"C= $token_data eq "printf"D= $token_data eq "say"
ABCDresult
0XXX0
10000
11XX1
101X1
10011
22 1 my @function_args;
23 1 ▶ for ($i++; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 2 0 2
24 2 my $token_type = $token->{type};
25 2 my $token_kind = $token->{kind};
26  
27 2 ▶ if ($token_type == SEMI_COLON) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 106) { } 1 1 2
elsif ($token_type == 107 or $token_type == 108) { } 0 1 1
28 1 last;
29 }
30 ▶ elsif ($token_type == LEFT_PAREN || $token_type == RIGHT_PAREN) {
Condition33%1/3
$token_type == 107 or $token_type == 108
l!l&&r!l&&!r
001
MC/DC0%0/2
$token_type == 107 or $token_type == 108
$token_type == 107 $token_type == 108
Truth table33%1/3
A or B
A= $token_type == 107B= $token_type == 108
ABresult
1X1
011
000
31 0 next;
32 }
33  
34 1 push @function_args, $token;
35 }
36  
37 1 ▶ if (scalar @function_args > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @function_args > 1) 0 1 1
38 0 my $first_arg = $function_args[0];
39 0 my $first_arg_type = $first_arg->{type};
40 0 my $second_arg = $function_args[1];
41 0 my $second_arg_type = $second_arg->{type};
42 0 my $second_arg_kind = $second_arg->{kind};
43 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($first_arg_type == 194 || $first_arg_type == 191 || $first_arg_type == 166 || $first_arg_type == 122 and $second_arg_kind != 1 and $second_arg_type != 104 and $second_arg_type != 9) 0 0 0
Condition0%0/18
$first_arg_type == 194 || $first_arg_type == 191 || $first_arg_type == 166 || $first_arg_type == 122 and $second_arg_kind != 1 and $second_arg_type != 104 and $second_arg_type != 9
!ll&&!rl&&r
000
$first_arg_type == 194 || $first_arg_type == 191 || $first_arg_type == 166 || $first_arg_type == 122 and $second_arg_kind != 1 and $second_arg_type != 104
!ll&&!rl&&r
000
$first_arg_type == 194 || $first_arg_type == 191 || $first_arg_type == 166 || $first_arg_type == 122 and $second_arg_kind != 1
!ll&&!rl&&r
000
$first_arg_type == 194 or $first_arg_type == 191 or $first_arg_type == 166 or $first_arg_type == 122
l!l&&r!l&&!r
000
$first_arg_type == 194 or $first_arg_type == 191 or $first_arg_type == 166
l!l&&r!l&&!r
000
$first_arg_type == 194 or $first_arg_type == 191
l!l&&r!l&&!r
000
MC/DC0%0/7
$first_arg_type == 194 || $first_arg_type == 191 || $first_arg_type == 166 || $first_arg_type == 122 and $second_arg_kind != 1 and $second_arg_type != 104 and $second_arg_type != 9
$first_arg_type == 194 $first_arg_type == 191 $first_arg_type == 166 $first_arg_type == 122 $second_arg_kind != 1 $second_arg_type != 104 $second_arg_type != 9
Truth table0%0/17
A or B or C or D and E and F and G
A= $first_arg_type == 194B= $first_arg_type == 191C= $first_arg_type == 166D= $first_arg_type == 122E= $second_arg_kind != 1F= $second_arg_type != 104G= $second_arg_type != 9
ABCDEFGresult
0000XXX0
1XXX0XX0
01XX0XX0
001X0XX0
00010XX0
1XXX10X0
01XX10X0
001X10X0
000110X0
1XXX1100
01XX1100
001X1100
00011100
1XXX1111
01XX1111
001X1111
00011111
44 (
45 $first_arg_type == GLOBAL_VAR ||
46 $first_arg_type == LOCAL_VAR ||
47 $first_arg_type == VAR ||
48 $first_arg_type == KEY
49 ) &&
50 $second_arg_kind != KIND_OP &&
51 $second_arg_type != COMMA &&
52 $second_arg_type != STRING_ADD
53 ) {
54 push @violations, {
55 filename => $file,
56 line => $token->{line},
57 0 description => DESC,
58 explanation => EXPL,
59 policy => __PACKAGE__,
60 };
61 }
62 }
63 }
64  
65 }
66  
67 2 return \@violations;
68 }
69  
70 3 1;
71  
« Perl/Lint/Policy/Subroutines/ProhibitNestedSubs.pm ↑ Summary Perl/Lint/Policy/ControlStructures/ProhibitPostfixControls.pm »