Perl/Lint/Policy/ValuesAndExpressions/ProhibitLongChainsOfMethodCalls.pm

filter: Statementstmt 80.5% 29 / 36 Branchbran 58.3% 7 / 12 Conditioncond 33.3% 3 / 9 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 67.6% 48 / 71 CC 10 SCAR 25.9
CC
10
Cov
68%
evaluate
20.6
BEGIN
1.0
BEGIN
1.0
CRAP 13.3
« Perl/Lint/Policy/RegularExpressions/RequireBracesForMultiline.pm ↑ Summary Test/Perl/Lint.pm »
1 package Perl::Lint::Policy::ValuesAndExpressions::ProhibitLongChainsOfMethodCalls;
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 => 'The number of chained calls to allow',
10 EXPL => 'Long chains of method calls indicate code that is too tightly coupled',
11 3 };
12  
13 2 ▶sub evaluate {
Subroutine evaluate: called CC=10 SCAR=30.3
Pod undocumented
14 2 my ($class, $file, $tokens, $src, $args) = @_;
15  
16 2 my $max_chain_length = 3;
17 2 ▶ if (my $this_policies_arg = $args->{prohibit_long_chains_of_method_calls}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $this_policies_arg = $args->{"prohibit_long_chains_of_method_calls"}) 0 2 2
18 0 ▶ $max_chain_length = $this_policies_arg->{max_chain_length} || $max_chain_length;
Condition0%0/3
$this_policies_arg->{'max_chain_length'} || $max_chain_length
l!l&&r!l&&!r
000
MC/DC0%0/2
$this_policies_arg->{'max_chain_length'} || $max_chain_length
$this_policies_arg->{'max_chain_length'} $max_chain_length
Truth table0%0/3
A || B
A= $this_policies_arg->{'max_chain_length'}B= $max_chain_length
ABresult
1X1
011
000
19 }
20  
21 2 my @violations;
22 2 ▶ for (my $i = 0, my $token_type, my $num_of_chain = 0; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 51 2 53
23 51 $token_type = $token->{type};
24  
25 51 ▶ if ($token_type == POINTER) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 125) { } 0 51 51
elsif ($token_type == 106 or $token->{'kind'} == 17) { } 12 39 51
26 0 my $next_token = $tokens->[$i+1];
27 0 my $next_token_type = $next_token->{type};
28 0 ▶ if ($next_token_type == LEFT_BRACE || $next_token_type == LEFT_BRACKET) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_token_type == 109 or $next_token_type == 111) 0 0 0
Condition0%0/3
$next_token_type == 109 or $next_token_type == 111
l!l&&r!l&&!r
000
MC/DC0%0/2
$next_token_type == 109 or $next_token_type == 111
$next_token_type == 109 $next_token_type == 111
Truth table0%0/3
A or B
A= $next_token_type == 109B= $next_token_type == 111
ABresult
1X1
011
000
29 # array and hash ref chains. They should be ignored.
30 0 next;
31 }
32  
33 0 $num_of_chain++;
34 }
35 ▶ elsif ($token_type == SEMI_COLON || $token->{kind} == KIND_STMT) {
Condition100%3/3
$token_type == 106 or $token->{"kind"} == 17
l!l&&r!l&&!r
11139
MC/DC100%2/2
$token_type == 106 or $token->{"kind"} == 17
$token_type == 106 $token->{"kind"} == 17
Truth table100%3/3
A or B
A= $token_type == 106B= $token->{"kind"} == 17
ABresult
1X1
011
000
36 12 ▶ if ($num_of_chain > $max_chain_length) {
Branch: 1 branch
BranchTrueFalseTotal
if ($num_of_chain > $max_chain_length) 0 12 12
37 push @violations, {
38 filename => $file,
39 line => $token->{line},
40 0 description => DESC,
41 explanation => EXPL,
42 policy => __PACKAGE__,
43 };
44 }
45 12 $num_of_chain = 0;
46 }
47 }
48  
49 2 return \@violations;
50 }
51  
52 3 1;
53  
« Perl/Lint/Policy/RegularExpressions/RequireBracesForMultiline.pm ↑ Summary Test/Perl/Lint.pm »