Conditions | 10 |
Paths | 7 |
Total Lines | 28 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Tests | 15 |
CRAP Score | 10 |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
19 | 26 | public function validate(AnnotationMetadata $metadata, Scope $scope) : void |
|
20 | { |
||
21 | 26 | $target = $metadata->getTarget(); |
|
22 | |||
23 | 26 | if ($target->all()) { |
|
24 | 16 | return; |
|
25 | } |
||
26 | |||
27 | 11 | if ($scope->isNested()) { |
|
28 | 4 | if (! $target->annotation()) { |
|
29 | 3 | throw InvalidTarget::annotation($metadata); |
|
30 | } |
||
31 | |||
32 | 1 | return; |
|
33 | } |
||
34 | |||
35 | 7 | $subject = $scope->getSubject(); |
|
36 | |||
37 | 7 | if ($subject instanceof ReflectionClass && ! $target->class()) { |
|
38 | 1 | throw InvalidTarget::class($metadata); |
|
39 | } |
||
40 | |||
41 | 6 | if ($subject instanceof ReflectionProperty && ! $target->property()) { |
|
42 | 1 | throw InvalidTarget::property($metadata); |
|
43 | } |
||
44 | |||
45 | 5 | if ($subject instanceof ReflectionMethod && ! $target->method()) { |
|
46 | 1 | throw InvalidTarget::method($metadata); |
|
47 | } |
||
52 |