lib/Perl/Critic/Policy/Misc/ProhibitMethodsInStringConcat.pm

filter: Statementstmt 94.2% 33 / 35 Branchbran 78.5% 11 / 14 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 90.0% 9 / 10 Podpod 100% 4 / 4 totaltotal 80.8% 59 / 73 CC 10 SCAR 13.5
CC
10
Cov
84%
violates
6.4
__ANON__
5.2
default_themes
2.0
CRAP 3.9
↑ Summary
1 #!/bin/false
2 # ABSTRACT: Prohibit method calls in string concatenation
3 # PODNAME: Perl::Critic::Policy::Misc::ProhibitMethodsInStringConcat
4  
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 package Perl::Critic::Policy::Misc::ProhibitMethodsInStringConcat;
9 2 $Perl::Critic::Policy::Misc::ProhibitMethodsInStringConcat::VERSION = '0.02';
10 2 ▶use parent 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶use Perl::Critic::Utils qw(:severities);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 9 ▶sub default_severity { return $SEVERITY_MEDIUM; }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
17 0 ▶sub default_themes { return qw(misc); }
Subroutine default_themes: not called CC=1 SCAR=6.9
Pod documented
18 12 ▶sub applies_to { return 'PPI::Token::Operator'; }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
19  
20 25 ▶sub violates {
Subroutine violates: called CC=6 SCAR=18.6
Pod documented
21 25 my ( $self, $elem, undef ) = @_;
22  
23 25 ▶ return if $elem->content() ne q{.};
Branch: 1 branch
BranchTrueFalseTotal
if $elem->content ne "." 13 12 25
24  
25 12 my $stmt = $elem->parent();
26 12 ▶ while ( $stmt && !$stmt->isa('PPI::Statement') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stmt and not $stmt->isa("PPI::Statement")) 0 12 12
Condition33%1/3
$stmt and not $stmt->isa("PPI::Statement")
!ll&&!rl&&r
0120
MC/DC0%0/2
$stmt and not $stmt->isa("PPI::Statement")
$stmt not $stmt->isa("PPI::Statement")
Truth table33%1/3
A and not(B)
A= $stmtB= not $stmt->isa("PPI::Statement")
ABresult
0X0
100
111
27 0 $stmt = $stmt->parent();
28 }
29 12 ▶ return if !$stmt;
Branch: 1 branch
BranchTrueFalseTotal
unless $stmt 0 12 12
30  
31 my $found = $stmt->find(
32 157 ▶ sub {
Subroutine __ANON__: called CC=5 SCAR=16.5
33 157 my $node = $_[1];
34 157 ▶ return 0 if !$node->isa('PPI::Token::Operator');
Branch: 1 branch
BranchTrueFalseTotal
unless $node->isa("PPI::Token::Operator") 128 29 157
35 29 ▶ return 0 if $node->content() ne '->';
Branch: 1 branch
BranchTrueFalseTotal
if $node->content ne "->" 18 11 29
36 11 my $next = $node->snext_sibling();
37 11 ▶ return 0 if !$next || !$next->isa('PPI::Token::Word');
Branch: 1 branch
BranchTrueFalseTotal
unless $next and $next->isa("PPI::Token::Word") 0 11 11
Condition33%1/3
$next and $next->isa("PPI::Token::Word")
!ll&&!rl&&r
0011
MC/DC0%0/2
$next and $next->isa("PPI::Token::Word")
$next $next->isa("PPI::Token::Word")
Truth table33%1/3
A and B
A= $nextB= $next->isa("PPI::Token::Word")
ABresult
0X0
100
111
38 11 return 1;
39 }
40 12 );
41  
42 12 ▶ return if !$found;
Branch: 1 branch
BranchTrueFalseTotal
unless $found 3 9 12
43  
44 9 return $self->violation(
45 'Method call used in string concatenation',
46 'Assign the method result to a variable first. '
47 . 'Method calls in string concatenation lose the variable name in undef warnings - '
48 . 'Perl can only say "uninitialized value" without naming which call returned undef, '
49 . 'making debugging harder.',
50 $elem,
51 );
52 }
53  
54 2 1;
55  
56 __END__
↑ Summary