Conditions | 11 |
Paths | 34 |
Total Lines | 50 |
Code Lines | 39 |
Lines | 0 |
Ratio | 0 % |
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 declare(strict_types=1); |
||
54 | public function for( |
||
55 | string $namespace, |
||
56 | string $baseClass, |
||
57 | string $callingFile, |
||
58 | string ...$types |
||
59 | ): array { |
||
60 | assert(null !== $this->dissect); |
||
61 | $baseAnnotation = $this->annotationOf($baseClass); |
||
|
|||
62 | if ($baseAnnotation === null) { |
||
63 | throw BaseClassIsNotGeneric::cannotUse($baseClass); |
||
64 | } |
||
65 | $expectedCount = $baseAnnotation->count; |
||
66 | $typeArguments = []; |
||
67 | $skip = 0; |
||
68 | $genericTypeArgument = []; |
||
69 | foreach ($types as $type) { |
||
70 | $annotation = $this->annotationOf($type); |
||
71 | if ($annotation !== null) { |
||
72 | $skip += $annotation->count + ($skip === 0 ? 1 : 0); |
||
73 | } |
||
74 | if ($skip > 0) { |
||
75 | $genericTypeArgument[] = $this->shortNameOf($type); |
||
76 | $skip--; |
||
77 | if ($skip === 0) { |
||
78 | $genericType = sprintf( |
||
79 | '%s\\%s', |
||
80 | $namespace, |
||
81 | implode($this->separator, $genericTypeArgument) |
||
82 | ); |
||
83 | $this->loader->generate($this->dissect->typesFromFile( |
||
84 | $genericType, |
||
85 | $callingFile |
||
86 | )); |
||
87 | // @todo reset $genericTypeArgument |
||
88 | $typeArguments[] = $genericType; |
||
89 | } |
||
90 | continue; |
||
91 | } |
||
92 | if (!$this->primitives->includes($type) && !class_exists($type)) { |
||
93 | throw TypeArgumentNotFound::for($type, $baseClass, count($typeArguments)); |
||
94 | } |
||
95 | $typeArguments[] = $type; |
||
96 | } |
||
97 | if (count($typeArguments) > $expectedCount) { |
||
98 | throw UnexpectedTypeArgument::for($baseClass, count($typeArguments) - 1); |
||
99 | } |
||
100 | if (count($typeArguments) < $expectedCount) { |
||
101 | throw MissingTypeArgument::for($baseClass, count($typeArguments)); |
||
102 | } |
||
103 | return $typeArguments; |
||
104 | } |
||
125 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.