Policy/ValuesAndExpressions/RequireConstantOnLeftSideOfEquality.pm

filter: Statementstmt 100% 36 / 36 Branchbran 100% 8 / 8 Conditioncond 80.0% 8 / 10 MC/DCmcdc 66.6% 4 / 6 Subroutinesub 100% 12 / 12 Podpod 80.0% 4 / 5 totaltotal 93.5% 72 / 77 CC 9 SCAR 12.3
CC
9
Cov
96%
violates
7.0
_is_constant_like
3.0
BEGIN
1.0
CRAP 3.4
« Policy/ValuesAndExpressions/RestrictLongStrings.pm ↑ Summary Policy/Modules/RequirePerlVersion.pm »
1 ##############################################################################
2 # $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/lib/Perl/Critic/Policy/ValuesAndExpressions/RequireInterpolationOfMetachars.pm $
3 # $Date: 2008-07-07 09:09:13 -0700 (Mon, 07 Jul 2008) $
4 # $Author: clonezone $
5 # $Revision: 2537 $
6 ##############################################################################
7  
8 package Perl::Critic::Policy::ValuesAndExpressions::RequireConstantOnLeftSideOfEquality;
9  
10 7 ▶use 5.006001;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 7 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 7 ▶use Perl::Critic::Utils qw{ :severities };
Subroutine BEGIN: called CC=1 SCAR=0.0
18 7 ▶use base 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 #-----------------------------------------------------------------------------
21  
22 7 our $VERSION = '1.003';
23  
24 #-----------------------------------------------------------------------------
25  
26 7 Readonly::Scalar my $DESC => q{Constant value on right side of equality};
27 7 Readonly::Scalar my $EXPL =>
28 q{Putting the constant on the left exposes typos};
29  
30 #-----------------------------------------------------------------------------
31  
32 4 ▶sub supported_parameters { return () }
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
33 7 ▶sub default_severity { return $SEVERITY_LOW }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
34 1 ▶sub default_themes { return qw(more) }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
35 3 ▶sub applies_to { return qw(PPI::Token::Operator) }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
36  
37 #-----------------------------------------------------------------------------
38  
39 18 ▶sub violates {
Subroutine violates: called CC=7 SCAR=19.5
Pod documented
40 18 my ( $self, $elem, undef ) = @_;
41 18 ▶ return if !( q<==> eq $elem || q<eq> eq $elem );
Branch: 1 branch
BranchTrueFalseTotal
unless "==" eq $elem or "eq" eq $elem 3 15 18
Condition100%3/3
"==" eq $elem or "eq" eq $elem
l!l&&r!l&&!r
963
MC/DC100%2/2
"==" eq $elem or "eq" eq $elem
"==" eq $elem "eq" eq $elem
Truth table100%3/3
A or B
A= "==" eq $elemB= "eq" eq $elem
ABresult
1X1
011
000
42  
43 15 ▶ my $right_sib = $elem->snext_sibling() || return;
Condition50%1/2
$elem->snext_sibling || (return)
l!l
150
MC/DC0%0/1
$elem->snext_sibling || (return)
$elem->snext_sibling
Truth table50%1/2
A
A= $elem->snext_sibling
Aresult
11
00
44 15 ▶ my $left_sib = $elem->sprevious_sibling() || return;
Condition50%1/2
$elem->sprevious_sibling || (return)
l!l
150
MC/DC0%0/1
$elem->sprevious_sibling || (return)
$elem->sprevious_sibling
Truth table50%1/2
A
A= $elem->sprevious_sibling
Aresult
11
00
45  
46 15 ▶ if ( !_is_constant_like($left_sib) && _is_constant_like($right_sib) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not _is_constant_like($left_sib) and _is_constant_like($right_sib)) 6 9 15
Condition100%3/3
not _is_constant_like($left_sib) and _is_constant_like($right_sib)
!ll&&!rl&&r
636
MC/DC100%2/2
not _is_constant_like($left_sib) and _is_constant_like($right_sib)
not _is_constant_like($left_sib) _is_constant_like($right_sib)
Truth table100%3/3
not(A) and B
A= not _is_constant_like($left_sib)B= _is_constant_like($right_sib)
ABresult
0X0
100
111
47 6 return $self->violation( $DESC, $EXPL, $right_sib );
48 }
49  
50 9 return; # ok!
51 }
52  
53 #-----------------------------------------------------------------------------
54  
55 24 ▶sub _is_constant_like {
Subroutine _is_constant_like: called CC=3 SCAR=11.0
56 24 my $elem = shift;
57 24 ▶ return 1 if $elem->isa('PPI::Token::Number');
Branch: 1 branch
BranchTrueFalseTotal
if $elem->isa("PPI::Token::Number") 6 18 24
58 18 ▶ return 1 if $elem->isa('PPI::Token::Quote');
Branch: 1 branch
BranchTrueFalseTotal
if $elem->isa("PPI::Token::Quote") 6 12 18
59 12 return 0;
60 }
61  
62 7 1;
63  
64 __END__
« Policy/ValuesAndExpressions/RestrictLongStrings.pm ↑ Summary Policy/Modules/RequirePerlVersion.pm »