lib/Perl/Critic/Policy/ValuesAndExpressions/ProhibitMagicNumbers.pm

filter: Statementstmt 40.5% 71 / 175 Branchbran 6.5% 8 / 122 Conditioncond 0.0% 0 / 26 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 68.1% 15 / 22 Podpod 85.7% 6 / 7 totaltotal 27.4% 100 / 365 CC 73 SCAR 48.5
CC
73
Cov
24%
_element_is_in_a_constant_subroutine
306.0
violates
240.0
_element_is_in_an_include_readonly_or_version_statement
132.0
CRAP 127.3
« lib/Perl/Critic/Policy/RegularExpressions/ProhibitUnusedCapture.pm ↑ Summary lib/Perl/Critic/Policy/InputOutput/RequireBriefOpen.pm »
1 package Perl::Critic::Policy::ValuesAndExpressions::ProhibitMagicNumbers;
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  
7 40 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 40 ▶use Perl::Critic::Utils qw{ :booleans :characters :severities :data_conversion };
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 =>
18 q{Unnamed numeric literals make code less maintainable};
19 40 Readonly::Scalar my $USE_READONLY_OR_CONSTANT =>
20 ' Use the Readonly or Const::Fast module or the "constant" pragma instead';
21 40 Readonly::Scalar my $TYPE_NOT_ALLOWED_SUFFIX =>
22 ") are not allowed.$USE_READONLY_OR_CONSTANT";
23  
24 40 Readonly::Scalar my $UNSIGNED_NUMBER =>
25 qr{
26 \d+ (?: [$PERIOD] \d+ )? # 1, 1.5, etc.
27 | [$PERIOD] \d+ # .3, .7, etc.
28 }xms;
29 40 Readonly::Scalar my $SIGNED_NUMBER => qr/ [-+]? $UNSIGNED_NUMBER /xms;
30  
31 40 Readonly::Scalar my $RANGE =>
32 qr{
33 \A
34 ($SIGNED_NUMBER)
35 [$PERIOD] [$PERIOD]
36 ($SIGNED_NUMBER)
37 (?:
38 [$COLON] by [$LEFT_PAREN]
39 ($UNSIGNED_NUMBER)
40 [$RIGHT_PAREN]
41 )?
42 \z
43 }xms;
44  
45 40 Readonly::Scalar my $SPECIAL_ARRAY_SUBSCRIPT_EXEMPTION => -1;
46  
47 #----------------------------------------------------------------------------
48  
49 94 ▶sub supported_parameters {
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
50 return (
51 {
52 94 name => 'allowed_values',
53 description => 'Individual and ranges of values to allow, and/or "all_integers".',
54 default_string => '0 1 2',
55 parser => \&_parse_allowed_values,
56 },
57 {
58 name => 'allowed_types',
59 description => 'Kind of literals to allow.',
60 default_string => 'Float',
61 behavior => 'enumeration',
62 enumeration_values => [ qw{ Binary Exp Float Hex Octal } ],
63 enumeration_allow_multiple_values => 1,
64 },
65 {
66 name => 'allow_to_the_right_of_a_fat_comma',
67 description =>
68 q[Should anything to the right of a "=>" be allowed?],
69 default_string => '1',
70 behavior => 'boolean',
71 },
72 {
73 name => 'constant_creator_subroutines',
74 description => q{Names of subroutines that create constants},
75 behavior => 'string list',
76 list_always_present_values => [
77 qw<
78 Readonly Readonly::Scalar Readonly::Array Readonly::Hash
79 const
80 >,
81 ],
82 },
83 );
84 }
85  
86 74 ▶sub default_severity { return $SEVERITY_LOW }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
87 73 ▶sub default_themes { return qw( core maintenance certrec ) }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
88 2 ▶sub applies_to { return 'PPI::Token::Number' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
89  
90 5 ▶sub default_maximum_violations_per_document { return 10; }
Subroutine default_maximum_violations_per_document: called CC=1 SCAR=0.0
Pod documented
91  
92 #----------------------------------------------------------------------------
93  
94 25 ▶sub initialize_if_enabled {
Subroutine initialize_if_enabled: called CC=1 SCAR=0.0
Pod documented
95 25 my ($self, undef) = @_;
96  
97 25 $self->_determine_checked_types();
98  
99 25 return $TRUE;
100 }
101  
102 92 ▶sub _parse_allowed_values {
Subroutine _parse_allowed_values: called CC=3 SCAR=12.4
103 92 my ($self, undef, $config_string) = @_;
104  
105 92 my ( $all_integers_allowed, $allowed_values )
106 = _determine_allowed_values($config_string);
107  
108 92 my $allowed_string = ' is not one of the allowed literal values (';
109 92 ▶ if ($all_integers_allowed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($all_integers_allowed) 0 92 92
110 0 $allowed_string .= 'all integers';
111  
112 0 ▶ if ( %{$allowed_values} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (%{$allowed_values;}) 0 0 0
113 0 $allowed_string .= ', ';
114 }
115 }
116 $allowed_string
117 92 .= ( join ', ', sort { $a <=> $b } keys %{$allowed_values} ) . ').'
118 . $USE_READONLY_OR_CONSTANT;
119  
120 92 $self->{_allowed_values} = $allowed_values;
121 92 $self->{_all_integers_allowed} = $all_integers_allowed;
122 92 $self->{_allowed_string} = $allowed_string;
123  
124 92 return;
125 }
126  
127 92 ▶sub _determine_allowed_values {
Subroutine _determine_allowed_values: called CC=10 SCAR=30.7
128 92 my ($config_string) = @_;
129  
130 92 my @allowed_values;
131 my @potential_allowed_values;
132 92 my $all_integers_allowed = 0;
133  
134 92 ▶ if ( defined $config_string ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $config_string) { } 2 90 92
135 my @allowed_values_strings =
136 2 grep {$_} split m/\s+/xms, $config_string;
137  
138 2 foreach my $value_string (@allowed_values_strings) {
139 4 ▶ if ($value_string eq 'all_integers') {
Branch: 3 branches
BranchTrueFalseTotal
if ($value_string eq 'all_integers') { } 0 4 4
elsif ($value_string =~ / \A $SIGNED_NUMBER \z /msx) { } 4 0 4
elsif ($value_string =~ /$RANGE/msx) { } 0 0 0
140 0 $all_integers_allowed = 1;
141 } elsif ( $value_string =~ m/ \A $SIGNED_NUMBER \z /xms ) {
142 4 push @potential_allowed_values, $value_string + 0;
143 } elsif ( $value_string =~ m/$RANGE/xms ) {
144 0 my ( $minimum, $maximum, $increment ) = ($1, $2, $3);
145 0 ▶ $increment ||= 1;
Condition0%0/2
$increment ||= 1
l!l
00
MC/DC0%0/1
$increment ||= 1
$increment
Truth table0%0/2
A
A= $increment
Aresult
11
00
146  
147 0 $minimum += 0;
148 0 $maximum += 0;
149 0 $increment += 0;
150  
151 0 ▶ for ( ## no critic (ProhibitCStyleForLoops)
Branch: 1 branch
BranchTrueFalseTotal
if ($value <= $maximum) 0 0 0
152 my $value = $minimum;
153 $value <= $maximum;
154 $value += $increment
155 ) {
156 0 push @potential_allowed_values, $value;
157 }
158 } else {
159 0 die q{Invalid value for allowed_values: }, $value_string,
160 q{. Must be a number, a number range, or},
161 qq{ "all_integers".\n};
162 }
163 }
164  
165 2 ▶ if ($all_integers_allowed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($all_integers_allowed) { } 0 2 2
166 0 @allowed_values = grep { $_ != int $_ } @potential_allowed_values; ## no critic ( BuiltinFunctions::ProhibitUselessTopic )
167 } else {
168 2 @allowed_values = @potential_allowed_values;
169 }
170 } else {
171 90 @allowed_values = (2);
172 }
173  
174 92 ▶ if ( not $all_integers_allowed ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($all_integers_allowed) 92 0 92
175 92 push @allowed_values, 0, 1;
176 }
177 92 my %allowed_values = hashify(@allowed_values);
178  
179 92 return ( $all_integers_allowed, \%allowed_values );
180 }
181  
182 25 ▶sub _determine_checked_types {
Subroutine _determine_checked_types: called CC=3 SCAR=11.1
183 25 my ($self) = @_;
184  
185 25 my %checked_types = (
186 'PPI::Token::Number::Binary' => 'Binary literals (',
187 'PPI::Token::Number::Float' => 'Floating-point literals (',
188 'PPI::Token::Number::Exp' => 'Exponential literals (',
189 'PPI::Token::Number::Hex' => 'Hexadecimal literals (',
190 'PPI::Token::Number::Octal' => 'Octal literals (',
191 'PPI::Token::Number::Version' => 'Version literals (',
192 );
193  
194 # This will be set by the enumeration behavior specified in
195 # supported_parameters() above.
196 25 my $allowed_types = $self->{_allowed_types};
197  
198 25 foreach my $allowed_type ( keys %{$allowed_types} ) {
199 25 delete $checked_types{"PPI::Token::Number::$allowed_type"};
200  
201 25 ▶ if ( $allowed_type eq 'Exp' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($allowed_type eq "Exp") 0 25 25
202  
203 # because an Exp isa(Float).
204 0 delete $checked_types{'PPI::Token::Number::Float'};
205 }
206 }
207  
208 25 $self->{_checked_types} = \%checked_types;
209  
210 25 return;
211 }
212  
213  
214 0 ▶sub violates {
Subroutine violates: not called CC=15 SCAR=54.8
Pod documented
215 0 my ( $self, $elem, undef ) = @_;
216  
217 0 ▶ if ( $self->{_allow_to_the_right_of_a_fat_comma} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_allow_to_the_right_of_a_fat_comma"}) 0 0 0
218 0 ▶ return if _element_is_to_the_right_of_a_fat_comma($elem);
Branch: 1 branch
BranchTrueFalseTotal
if _element_is_to_the_right_of_a_fat_comma($elem) 0 0 0
219 }
220  
221 0 ▶ return if _element_is_in_an_include_readonly_or_version_statement(
Branch: 1 branch
BranchTrueFalseTotal
if _element_is_in_an_include_readonly_or_version_statement($self, $elem) 0 0 0
222 $self, $elem,
223 );
224 0 ▶ return if _element_is_in_a_plan_statement($elem);
Branch: 1 branch
BranchTrueFalseTotal
if _element_is_in_a_plan_statement($elem) 0 0 0
225 0 ▶ return if _element_is_in_a_constant_subroutine($elem);
Branch: 1 branch
BranchTrueFalseTotal
if _element_is_in_a_constant_subroutine($elem) 0 0 0
226 0 ▶ return if _element_is_a_package_statement_version_number($elem);
Branch: 1 branch
BranchTrueFalseTotal
if _element_is_a_package_statement_version_number($elem) 0 0 0
227  
228 0 my $literal = $elem->literal();
229 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (defined $literal and not $self->{"_all_integers_allowed"} && int $literal == $literal and not defined $self->{"_allowed_values"}{$literal} and not _element_is_sole_component_of_a_subscript($elem) && $literal == $SPECIAL_ARRAY_SUBSCRIPT_EXEMPTION) 0 0 0
Condition0%0/15
defined $literal and not $self->{"_all_integers_allowed"} && int $literal == $literal and not defined $self->{"_allowed_values"}{$literal} and not _element_is_sole_component_of_a_subscript($elem) && $literal == $SPECIAL_ARRAY_SUBSCRIPT_EXEMPTION
!ll&&!rl&&r
000
defined $literal and not $self->{"_all_integers_allowed"} && int $literal == $literal and not defined $self->{"_allowed_values"}{$literal}
!ll&&!rl&&r
000
defined $literal and not $self->{"_all_integers_allowed"} && int $literal == $literal
!ll&&!rl&&r
000
$self->{'_all_integers_allowed'} && int $literal == $literal
!ll&&!rl&&r
000
_element_is_sole_component_of_a_subscript($elem) && $literal == $SPECIAL_ARRAY_SUBSCRIPT_EXEMPTION
!ll&&!rl&&r
000
MC/DC0%0/6
defined $literal and not $self->{"_all_integers_allowed"} && int $literal == $literal and not defined $self->{"_allowed_values"}{$literal} and not _element_is_sole_component_of_a_subscript($elem) && $literal == $SPECIAL_ARRAY_SUBSCRIPT_EXEMPTION
defined $literal $self->{'_all_integers_allowed'} int $literal == $literal not defined $self->{"_allowed_values"}{$literal} _element_is_sole_component_of_a_subscript($elem) $literal == $SPECIAL_ARRAY_SUBSCRIPT_EXEMPTION
Truth table0%0/10
A and not(B && C) and not(D) and not(E && F)
A= defined $literalB= $self->{'_all_integers_allowed'}C= int $literal == $literalD= not defined $self->{"_allowed_values"}{$literal}E= _element_is_sole_component_of_a_subscript($elem)F= $literal == $SPECIAL_ARRAY_SUBSCRIPT_EXEMPTION
ABCDEFresult
0XXXXX0
111XXX0
10X0XX0
1100XX0
10X1110
1101110
10X10X1
10X1101
11010X1
1101101
230 defined $literal
231 and not (
232 $self->{_all_integers_allowed}
233 and int $literal == $literal
234 )
235 and not defined $self->{_allowed_values}{$literal}
236 and not (
237 _element_is_sole_component_of_a_subscript($elem)
238 and $literal == $SPECIAL_ARRAY_SUBSCRIPT_EXEMPTION
239 )
240 ) {
241 return
242 $self->violation(
243 $elem->content() . $self->{_allowed_string},
244 0 $EXPL,
245 $elem,
246 );
247 }
248  
249  
250 0 my ( $number_type, $type_string );
251  
252 0 ▶ while (
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$self{"_checked_types"};}) 0 0 0
253 0 ( $number_type, $type_string ) = ( each %{ $self->{_checked_types} } )
254 ) {
255 0 ▶ if ( $elem->isa($number_type) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->isa($number_type)) 0 0 0
256 return
257 0 $self->violation(
258 $type_string . $elem->content() . $TYPE_NOT_ALLOWED_SUFFIX,
259 $EXPL,
260 $elem,
261 );
262 }
263 }
264  
265 0 return;
266 }
267  
268 0 ▶sub _element_is_to_the_right_of_a_fat_comma {
Subroutine _element_is_to_the_right_of_a_fat_comma: not called CC=3 SCAR=24.8
269 0 my ($elem) = @_;
270  
271 0 ▶ my $previous = $elem->sprevious_sibling() or return;
Branch: 1 branch
BranchTrueFalseTotal
my $previous = $elem->sprevious_sibling or return 0 0 0
272  
273 0 ▶ $previous->isa('PPI::Token::Operator') or return;
Branch: 1 branch
BranchTrueFalseTotal
$previous->isa("PPI::Token::Operator") or return 0 0 0
274  
275 0 return $previous->content() eq q[=>];
276 }
277  
278 0 ▶sub _element_is_sole_component_of_a_subscript {
Subroutine _element_is_sole_component_of_a_subscript: not called CC=6 SCAR=37.4
279 0 my ($elem) = @_;
280  
281 0 my $parent = $elem->parent();
282 0 ▶ if ( $parent and $parent->isa('PPI::Statement::Expression') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parent and $parent->isa("PPI::Statement::Expression")) 0 0 0
Condition0%0/3
$parent and $parent->isa("PPI::Statement::Expression")
!ll&&!rl&&r
000
MC/DC0%0/2
$parent and $parent->isa("PPI::Statement::Expression")
$parent $parent->isa("PPI::Statement::Expression")
Truth table0%0/3
A and B
A= $parentB= $parent->isa("PPI::Statement::Expression")
ABresult
0X0
100
111
283 0 ▶ if ( $parent->schildren() > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parent->schildren > 1) 0 0 0
284 0 return 0;
285 }
286  
287 0 my $grandparent = $parent->parent();
288 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($grandparent and $grandparent->isa("PPI::Structure::Subscript")) 0 0 0
Condition0%0/3
$grandparent and $grandparent->isa("PPI::Structure::Subscript")
!ll&&!rl&&r
000
MC/DC0%0/2
$grandparent and $grandparent->isa("PPI::Structure::Subscript")
$grandparent $grandparent->isa("PPI::Structure::Subscript")
Truth table0%0/3
A and B
A= $grandparentB= $grandparent->isa("PPI::Structure::Subscript")
ABresult
0X0
100
111
289 $grandparent
290 and $grandparent->isa('PPI::Structure::Subscript')
291 ) {
292 0 return 1;
293 }
294 }
295  
296 0 return 0;
297 }
298  
299 0 ▶sub _element_is_in_an_include_readonly_or_version_statement {
Subroutine _element_is_in_an_include_readonly_or_version_statement: not called CC=11 SCAR=48.8
300 0 my ($self, $elem) = @_;
301  
302 0 my $parent = $elem->parent();
303 0 ▶ while ($parent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parent) 0 0 0
304 0 ▶ if ( $parent->isa('PPI::Statement') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parent->isa("PPI::Statement")) 0 0 0
305 0 ▶ return 1 if $parent->isa('PPI::Statement::Include');
Branch: 1 branch
BranchTrueFalseTotal
if $parent->isa("PPI::Statement::Include") 0 0 0
306  
307 0 ▶ if ( $parent->isa('PPI::Statement::Variable') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parent->isa("PPI::Statement::Variable")) 0 0 0
308 0 ▶ if ( $parent->type() eq 'our' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parent->type eq "our") 0 0 0
309 0 my @variables = $parent->variables();
310 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @variables == 1 and $variables[0] eq "\$VERSION") 0 0 0
Condition0%0/3
scalar @variables == 1 and $variables[0] eq "\$VERSION"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @variables == 1 and $variables[0] eq "\$VERSION"
scalar @variables == 1 $variables[0] eq "\$VERSION"
Truth table0%0/3
A and B
A= scalar @variables == 1B= $variables[0] eq "\$VERSION"
ABresult
0X0
100
111
311 scalar @variables == 1
312 and $variables[0] eq '$VERSION' ## no critic (RequireInterpolationOfMetachars)
313 ) {
314 0 return 1;
315 }
316 }
317  
318 0 return 0;
319 }
320  
321 0 my $first_token = $parent->first_token();
322 0 ▶ if ( $first_token->isa('PPI::Token::Word') ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($first_token->isa('PPI::Token::Word')) { } 0 0 0
elsif ($parent->isa('PPI::Structure::Block')) { } 0 0 0
323 0 ▶ if ( $self->{_constant_creator_subroutines}{
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_constant_creator_subroutines"}{$first_token->content}) 0 0 0
324 $first_token->content() } ) {
325 0 return 1;
326 }
327 } elsif ($parent->isa('PPI::Structure::Block')) {
328 0 return 0;
329 }
330 }
331  
332 0 $parent = $parent->parent();
333 }
334  
335 0 return 0;
336 }
337  
338 # Allow "plan tests => 39;".
339  
340 40 Readonly::Scalar my $PLAN_STATEMENT_MINIMUM_TOKENS => 4;
341  
342 0 ▶sub _element_is_in_a_plan_statement {
Subroutine _element_is_in_a_plan_statement: not called CC=10 SCAR=47.0
343 0 my ($elem) = @_;
344  
345 0 my $parent = $elem->parent();
346 0 ▶ return 0 if not $parent;
Branch: 1 branch
BranchTrueFalseTotal
unless $parent 0 0 0
347  
348 0 ▶ return 0 if not $parent->isa('PPI::Statement');
Branch: 1 branch
BranchTrueFalseTotal
unless $parent->isa("PPI::Statement") 0 0 0
349  
350 0 my @children = $parent->schildren();
351 0 ▶ return 0 if @children < $PLAN_STATEMENT_MINIMUM_TOKENS;
Branch: 1 branch
BranchTrueFalseTotal
if @children < $PLAN_STATEMENT_MINIMUM_TOKENS 0 0 0
352  
353 0 ▶ return 0 if not $children[0]->isa('PPI::Token::Word');
Branch: 1 branch
BranchTrueFalseTotal
unless $children[0]->isa("PPI::Token::Word") 0 0 0
354 0 ▶ return 0 if $children[0]->content() ne 'plan';
Branch: 1 branch
BranchTrueFalseTotal
if $children[0]->content ne "plan" 0 0 0
355  
356 0 ▶ return 0 if not $children[1]->isa('PPI::Token::Word');
Branch: 1 branch
BranchTrueFalseTotal
unless $children[1]->isa("PPI::Token::Word") 0 0 0
357 0 ▶ return 0 if $children[1]->content() ne 'tests';
Branch: 1 branch
BranchTrueFalseTotal
if $children[1]->content ne "tests" 0 0 0
358  
359 0 ▶ return 0 if not $children[2]->isa('PPI::Token::Operator');
Branch: 1 branch
BranchTrueFalseTotal
unless $children[2]->isa("PPI::Token::Operator") 0 0 0
360 0 ▶ return 0 if $children[2]->content() ne '=>';
Branch: 1 branch
BranchTrueFalseTotal
if $children[2]->content ne "=>" 0 0 0
361  
362 0 return 1;
363 }
364  
365 0 ▶sub _element_is_in_a_constant_subroutine {
Subroutine _element_is_in_a_constant_subroutine: not called CC=17 SCAR=57.2
366 0 my ($elem) = @_;
367  
368 0 my $parent = $elem->parent();
369 0 ▶ return 0 if not $parent;
Branch: 1 branch
BranchTrueFalseTotal
unless $parent 0 0 0
370  
371 0 ▶ return 0 if not $parent->isa('PPI::Statement');
Branch: 1 branch
BranchTrueFalseTotal
unless $parent->isa("PPI::Statement") 0 0 0
372  
373 0 my $following = $elem->snext_sibling();
374 0 ▶ if ($following) {
Branch: 1 branch
BranchTrueFalseTotal
if ($following) 0 0 0
375 0 ▶ return 0 if not $following->isa('PPI::Token::Structure');
Branch: 1 branch
BranchTrueFalseTotal
unless $following->isa("PPI::Token::Structure") 0 0 0
376 0 ▶ return 0 if $following->content() ne $SCOLON;
Branch: 1 branch
BranchTrueFalseTotal
if $following->content ne $Perl::Critic::Policy::ValuesAndExpressions::ProhibitMagicNumbers::SCOLON 0 0 0
377 0 ▶ return 0 if $following->snext_sibling();
Branch: 1 branch
BranchTrueFalseTotal
if $following->snext_sibling 0 0 0
378 }
379  
380 0 my $preceding = $elem->sprevious_sibling();
381 0 ▶ if ($preceding) {
Branch: 1 branch
BranchTrueFalseTotal
if ($preceding) 0 0 0
382 0 ▶ return 0 if not $preceding->isa('PPI::Token::Word');
Branch: 1 branch
BranchTrueFalseTotal
unless $preceding->isa("PPI::Token::Word") 0 0 0
383 0 ▶ return 0 if $preceding->content() ne 'return';
Branch: 1 branch
BranchTrueFalseTotal
if $preceding->content ne "return" 0 0 0
384 0 ▶ return 0 if $preceding->sprevious_sibling();
Branch: 1 branch
BranchTrueFalseTotal
if $preceding->sprevious_sibling 0 0 0
385 }
386  
387 0 ▶ return 0 if $parent->snext_sibling();
Branch: 1 branch
BranchTrueFalseTotal
if $parent->snext_sibling 0 0 0
388 0 ▶ return 0 if $parent->sprevious_sibling();
Branch: 1 branch
BranchTrueFalseTotal
if $parent->sprevious_sibling 0 0 0
389  
390 0 my $grandparent = $parent->parent();
391 0 ▶ return 0 if not $grandparent;
Branch: 1 branch
BranchTrueFalseTotal
unless $grandparent 0 0 0
392  
393 0 ▶ return 0 if not $grandparent->isa('PPI::Structure::Block');
Branch: 1 branch
BranchTrueFalseTotal
unless $grandparent->isa("PPI::Structure::Block") 0 0 0
394  
395 0 my $greatgrandparent = $grandparent->parent();
396 0 ▶ return 0 if not $greatgrandparent;
Branch: 1 branch
BranchTrueFalseTotal
unless $greatgrandparent 0 0 0
397 0 ▶ return 0 if not $greatgrandparent->isa('PPI::Statement::Sub');
Branch: 1 branch
BranchTrueFalseTotal
unless $greatgrandparent->isa("PPI::Statement::Sub") 0 0 0
398  
399 0 return 1;
400 }
401  
402 0 ▶sub _element_is_a_package_statement_version_number {
Subroutine _element_is_a_package_statement_version_number: not called CC=4 SCAR=30.0
403 0 my ($elem) = @_;
404  
405 0 ▶ my $parent = $elem->statement()
Branch: 1 branch
BranchTrueFalseTotal
my $parent = $elem->statement or return 0 0 0 0
406 or return 0;
407  
408 0 ▶ $parent->isa( 'PPI::Statement::Package' )
Branch: 1 branch
BranchTrueFalseTotal
$parent->isa("PPI::Statement::Package") or return 0 0 0 0
409 or return 0;
410  
411 0 ▶ my $version = $parent->schild( 2 )
Branch: 1 branch
BranchTrueFalseTotal
my $version = $parent->schild(2) or return 0 0 0 0
412 or return 0;
413  
414 0 return $version == $elem;
415 }
416  
417 40 1;
418  
419 __END__
« lib/Perl/Critic/Policy/RegularExpressions/ProhibitUnusedCapture.pm ↑ Summary lib/Perl/Critic/Policy/InputOutput/RequireBriefOpen.pm »