« lib/Perl/Critic/Policy/ClassHierarchies/ProhibitOneArgBless.pm
↑ Summary
lib/Perl/Critic/Policy/ValuesAndExpressions/ProhibitNoisyQuotes.pm »
| 1 | package Perl::Critic::Policy::ValuesAndExpressions::ProhibitMixedBooleanOperators; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 40 | ▶ | use 5.010001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 40 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 40 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 40 | ▶ | use Readonly; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 40 | ▶ | use Perl::Critic::Utils qw{ :severities :data_conversion }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 40 | ▶ | use parent 'Perl::Critic::Policy'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 40 | our $VERSION = '1.156'; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 40 | Readonly::Hash my %LOW_BOOLEANS => hashify( qw( not or and ) ); | |||||||||||||||||||||||||||
| 19 | 40 | Readonly::Hash my %HIGH_BOOLEANS => hashify( qw( ! || && ||= &&= //=) ); | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 40 | Readonly::Hash my %EXEMPT_TYPES => hashify( | |||||||||||||||||||||||||||
| 22 | qw( | ||||||||||||||||||||||||||||
| 23 | PPI::Statement::Block | ||||||||||||||||||||||||||||
| 24 | PPI::Statement::Scheduled | ||||||||||||||||||||||||||||
| 25 | PPI::Statement::Package | ||||||||||||||||||||||||||||
| 26 | PPI::Statement::Include | ||||||||||||||||||||||||||||
| 27 | PPI::Statement::Sub | ||||||||||||||||||||||||||||
| 28 | PPI::Statement::Variable | ||||||||||||||||||||||||||||
| 29 | PPI::Statement::Compound | ||||||||||||||||||||||||||||
| 30 | PPI::Statement::Data | ||||||||||||||||||||||||||||
| 31 | PPI::Statement::End | ||||||||||||||||||||||||||||
| 32 | ) | ||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 40 | Readonly::Scalar my $DESC => q{Mixed high and low-precedence booleans}; | |||||||||||||||||||||||||||
| 38 | 40 | Readonly::Scalar my $EXPL => [ 70 ]; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 90 | ▶ | sub supported_parameters { return () } | ||||||||||||||||||||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 43 | 74 | ▶ | sub default_severity { return $SEVERITY_HIGH } | ||||||||||||||||||||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 44 | 91 | ▶ | sub default_themes { return qw( core bugs pbp certrec ) } | ||||||||||||||||||||||||||
|
Subroutine
default_themes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 45 | 33 | ▶ | sub applies_to { return 'PPI::Statement' } | ||||||||||||||||||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 296 | ▶ | sub violates { | ||||||||||||||||||||||||||
|
Subroutine
violates: called CC=4 SCAR=15.2
Pod
documented
| |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 296 | my ( $self, $elem, undef ) = @_; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | # PPI::Statement is the ancestor of several types of PPI elements. | ||||||||||||||||||||||||||||
| 54 | # But for this policy, we only want the ones that generally | ||||||||||||||||||||||||||||
| 55 | # represent a single statement or expression. There might be | ||||||||||||||||||||||||||||
| 56 | # better ways to do this, such as scanning for a semi-colon or | ||||||||||||||||||||||||||||
| 57 | # some other marker. | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 296 | ▶ | return if exists $EXEMPT_TYPES{ ref $elem }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 99 | ▶ | if ( $elem->find_first(\&_low_boolean) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$elem->find_first(\&Perl::Critic::Policy::ValuesAndExpressions::ProhibitMixedBooleanOperators::_low_boolean) and $elem->find_first(\&Perl::Critic::Policy::ValuesAndExpressions::ProhibitMixedBooleanOperators::_high_boolean)
MC/DC0%0/2
$elem->find_first(\&Perl::Critic::Policy::ValuesAndExpressions::ProhibitMixedBooleanOperators::_low_boolean) and $elem->find_first(\&Perl::Critic::Policy::ValuesAndExpressions::ProhibitMixedBooleanOperators::_high_boolean)
$elem->find_first(\&Perl::Critic::Policy::ValuesAndExpressions::ProhibitMixedBooleanOperators::_low_boolean)
$elem->find_first(\&Perl::Critic::Policy::ValuesAndExpressions::ProhibitMixedBooleanOperators::_high_boolean)
Truth table33%1/3
A and B
A= $elem->find_first(\&Perl::Critic::Policy::ValuesAndExpressions::ProhibitMixedBooleanOperators::_low_boolean)B= $elem->find_first(\&Perl::Critic::Policy::ValuesAndExpressions::ProhibitMixedBooleanOperators::_high_boolean)
| |||||||||||||||||||||||||||||
| 62 | && $elem->find_first(\&_high_boolean) ) { | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | return $self->violation( $DESC, $EXPL, $elem ); | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | 99 | return; #ok! | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 535 | ▶ | sub _low_boolean { | ||||||||||||||||||||||||||
|
Subroutine
_low_boolean: called CC=3 SCAR=11.4
| |||||||||||||||||||||||||||||
| 72 | 535 | my (undef, $elem) = @_; | |||||||||||||||||||||||||||
| 73 | 535 | ▶ | return if $elem->isa('PPI::Statement'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | return | ||||||||||||||||||||||||||||
| 76 | $elem->isa('PPI::Token::Operator') | ||||||||||||||||||||||||||||
| 77 | 535 | ▶ | && exists $LOW_BOOLEANS{$elem}; | ||||||||||||||||||||||||||
|
Condition66%2/3
$elem->isa('PPI::Token::Operator') && exists $LOW_BOOLEANS{$elem}
MC/DC0%0/2
$elem->isa('PPI::Token::Operator') && exists $LOW_BOOLEANS{$elem}
$elem->isa('PPI::Token::Operator')
exists $LOW_BOOLEANS{$elem}
Truth table66%2/3
A && B
A= $elem->isa('PPI::Token::Operator')B= exists $LOW_BOOLEANS{$elem}
| |||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | ▶ | sub _high_boolean { | ||||||||||||||||||||||||||
|
Subroutine
_high_boolean: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 83 | 0 | my (undef, $elem) = @_; | |||||||||||||||||||||||||||
| 84 | 0 | ▶ | return if $elem->isa('PPI::Statement'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | return | ||||||||||||||||||||||||||||
| 87 | $elem->isa('PPI::Token::Operator') | ||||||||||||||||||||||||||||
| 88 | 0 | ▶ | && exists $HIGH_BOOLEANS{$elem}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$elem->isa('PPI::Token::Operator') && exists $HIGH_BOOLEANS{$elem}
MC/DC0%0/2
$elem->isa('PPI::Token::Operator') && exists $HIGH_BOOLEANS{$elem}
$elem->isa('PPI::Token::Operator')
exists $HIGH_BOOLEANS{$elem}
Truth table0%0/3
A && B
A= $elem->isa('PPI::Token::Operator')B= exists $HIGH_BOOLEANS{$elem}
| |||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 40 | 1; | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | __END__ | ||||||||||||||||||||||||||||