| 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
| |||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 23 | 51 | $token_type = $token->{type}; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 51 | ▶ | if ($token_type == POINTER) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
$next_token_type == 109 or $next_token_type == 111
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
| |||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||
| 36 | 12 | ▶ | if ($num_of_chain > $max_chain_length) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||||