« lib/Perl/Critic/Policy/InputOutput/RequireCheckedOpen.pm
↑ Summary
lib/Perl/Critic/Policy/Miscellanea/ProhibitFormats.pm »
| 1 | package Perl::Critic::Policy::Subroutines::ProhibitExcessComplexity; | ||||||||||
| 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 :classification }; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 40 | ▶ | use Perl::Critic::Utils::McCabe qw{ calculate_mccabe_of_sub }; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 40 | ▶ | use parent 'Perl::Critic::Policy'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 40 | our $VERSION = '1.156'; | |||||||||
| 14 | |||||||||||
| 15 | #----------------------------------------------------------------------------- | ||||||||||
| 16 | |||||||||||
| 17 | 40 | Readonly::Scalar my $EXPL => q{Consider refactoring}; | |||||||||
| 18 | |||||||||||
| 19 | #----------------------------------------------------------------------------- | ||||||||||
| 20 | |||||||||||
| 21 | 91 | ▶ | sub supported_parameters { | ||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 22 | return ( | ||||||||||
| 23 | { | ||||||||||
| 24 | 91 | name => 'max_mccabe', | |||||||||
| 25 | description => 'The maximum complexity score allowed.', | ||||||||||
| 26 | default_string => '20', | ||||||||||
| 27 | behavior => 'integer', | ||||||||||
| 28 | integer_minimum => 1, | ||||||||||
| 29 | }, | ||||||||||
| 30 | ); | ||||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | 74 | ▶ | sub default_severity { return $SEVERITY_MEDIUM } | ||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 34 | 73 | ▶ | sub default_themes { return qw(core complexity maintenance) } | ||||||||
|
Subroutine
default_themes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 35 | 31 | ▶ | sub applies_to { return 'PPI::Statement::Sub' } | ||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 36 | |||||||||||
| 37 | #----------------------------------------------------------------------------- | ||||||||||
| 38 | |||||||||||
| 39 | 5 | ▶ | sub violates { | ||||||||
|
Subroutine
violates: called CC=3 SCAR=17.3
Pod
documented
| |||||||||||
| 40 | 5 | my ( $self, $elem, undef ) = @_; | |||||||||
| 41 | |||||||||||
| 42 | 5 | my $score = calculate_mccabe_of_sub( $elem ); | |||||||||
| 43 | |||||||||||
| 44 | # Is it too complex? | ||||||||||
| 45 | 5 | ▶ | return if $score <= $self->{_max_mccabe}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | |||||||||||
| 47 | 0 | my $desc; | |||||||||
| 48 | 0 | ▶ | if ( my $name = $elem->name() ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | 0 | $desc = qq<Subroutine "$name" with high complexity score ($score)>; | |||||||||
| 50 | } | ||||||||||
| 51 | else { | ||||||||||
| 52 | 0 | $desc = qq<Anonymous subroutine with high complexity score ($score)>; | |||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | 0 | return $self->violation( $desc, $EXPL, $elem ); | |||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | |||||||||||
| 59 | 40 | 1; | |||||||||
| 60 | |||||||||||
| 61 | __END__ | ||||||||||