line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use utf8; |
3
|
8
|
|
|
8
|
|
4780
|
|
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
42
|
|
4
|
|
|
|
|
|
|
use 5.010; |
5
|
8
|
|
|
8
|
|
276
|
|
|
8
|
|
|
|
|
24
|
|
6
|
|
|
|
|
|
|
use strict; |
7
|
8
|
|
|
8
|
|
35
|
use warnings; |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
127
|
|
8
|
8
|
|
|
8
|
|
34
|
|
|
8
|
|
|
|
|
22
|
|
|
8
|
|
|
|
|
667
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use Readonly; |
12
|
8
|
|
|
8
|
|
44
|
|
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
402
|
|
13
|
|
|
|
|
|
|
use Perl::Critic::Utils qw{ :severities :data_conversion :classification }; |
14
|
8
|
|
|
8
|
|
73
|
|
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
375
|
|
15
|
|
|
|
|
|
|
use base 'Perl::Critic::Policy'; |
16
|
8
|
|
|
8
|
|
2710
|
|
|
8
|
|
|
|
|
30
|
|
|
8
|
|
|
|
|
3011
|
|
17
|
|
|
|
|
|
|
Readonly::Scalar my $EXPL => q{Consider refactoring}; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
{ |
20
|
|
|
|
|
|
|
return $SEVERITY_MEDIUM; |
21
|
|
|
|
|
|
|
} |
22
|
8
|
|
|
8
|
1
|
76
|
|
23
|
|
|
|
|
|
|
{ |
24
|
|
|
|
|
|
|
return qw(complexity maintenance); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
0
|
1
|
0
|
{ |
28
|
|
|
|
|
|
|
return 'PPI::Statement::Sub'; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
{ |
32
|
13
|
|
|
13
|
1
|
183530
|
return ( |
33
|
|
|
|
|
|
|
{ 'name' => 'condition_count_limit', |
34
|
|
|
|
|
|
|
'description' => 'The maximum condition count allowed.', |
35
|
|
|
|
|
|
|
'default_string' => '3', |
36
|
|
|
|
|
|
|
'behavior' => 'integer', |
37
|
|
|
|
|
|
|
'integer_minimum' => 1, |
38
|
13
|
|
|
13
|
0
|
89805
|
}, |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
{ |
43
|
|
|
|
|
|
|
my ( $self, $elem, undef ) = @_; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $s = $elem->find( |
46
|
|
|
|
|
|
|
sub |
47
|
|
|
|
|
|
|
{ |
48
|
|
|
|
|
|
|
my ( undef, $element ) = @_; |
49
|
11
|
|
|
11
|
1
|
208
|
|
50
|
|
|
|
|
|
|
my $interesting = |
51
|
|
|
|
|
|
|
$element->isa( 'PPI::Structure::Condition' ) |
52
|
|
|
|
|
|
|
|| $element->isa( 'PPI::Structure::For' ) |
53
|
|
|
|
|
|
|
|| $element->isa( 'PPI::Structure::Given' ); |
54
|
783
|
|
|
783
|
|
6421
|
|
55
|
|
|
|
|
|
|
return $interesting; |
56
|
783
|
|
100
|
|
|
3630
|
} |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
if ( !$s ) { |
60
|
|
|
|
|
|
|
return; |
61
|
783
|
|
|
|
|
1423
|
} |
62
|
|
|
|
|
|
|
|
63
|
11
|
|
|
|
|
57
|
my $condition_count = @{ $s }; |
64
|
|
|
|
|
|
|
if ( $condition_count <= $self->{ '_condition_count_limit' } ) { |
65
|
11
|
100
|
|
|
|
132
|
return; |
66
|
1
|
|
|
|
|
4
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my $desc; |
69
|
10
|
|
|
|
|
18
|
if ( my $name = $elem->name() ) { |
|
10
|
|
|
|
|
18
|
|
70
|
10
|
100
|
|
|
|
24
|
$desc = qq<Subroutine "$name" with high condition count ($condition_count)>; |
71
|
2
|
|
|
|
|
7
|
} |
72
|
|
|
|
|
|
|
else { |
73
|
|
|
|
|
|
|
# never the case becaus no PPI::Statement::Sub |
74
|
8
|
|
|
|
|
14
|
$desc = qq<Anonymous subroutine with high condition count ($condition_count)>; |
75
|
8
|
50
|
|
|
|
34
|
} |
76
|
8
|
|
|
|
|
416
|
|
77
|
|
|
|
|
|
|
return $self->violation( $desc, $EXPL, $elem ); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
0
|
1; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
8
|
|
|
|
|
24
|
#----------------------------------------------------------------------------- |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=pod |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=encoding utf8 |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 NAME |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Perl::Critic::Policy::Mardem::ProhibitManyConditionsInSub |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 DESCRIPTION |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
This Policy counts the conditions within a sub. |
96
|
|
|
|
|
|
|
(more precise the PPI::Structure::Condition's, |
97
|
|
|
|
|
|
|
PPI::Structure::For's and PPI::Structure::Given's) |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 CONFIGURATION |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
The maximum acceptable Condition-Count can be set with the |
102
|
|
|
|
|
|
|
C<condition_count_limit> configuration item. Any sub with a count higher than |
103
|
|
|
|
|
|
|
this number will generate a policy violation. The default is 3. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
An example section for a F<.perlcriticrc>: |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
[Mardem::ProhibitManyConditionsInSub] |
108
|
|
|
|
|
|
|
condition_count_limit = 1 |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 AFFILIATION |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
This policy is part of L<Mardem::RefactoringPerlCriticPolicies>. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 AUTHOR |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Markus Demml, mardem@cpan.com |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Copyright (c) 2022, Markus Demml |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it |
123
|
|
|
|
|
|
|
under the same terms as the Perl 5 programming language system itself. |
124
|
|
|
|
|
|
|
The full text of this license can be found in the LICENSE file included |
125
|
|
|
|
|
|
|
with this module. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=cut |