Conditions | 10 |
Paths | 9 |
Total Lines | 46 |
Code Lines | 23 |
Lines | 0 |
Ratio | 0 % |
Tests | 20 |
CRAP Score | 10.4632 |
Changes | 2 | ||
Bugs | 0 | Features | 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 |
||
52 | 1 | private function resolveDependenciesRecursively(ReflectionParameter $parameter) |
|
53 | { |
||
54 | 1 | if (!$parameter->hasType()) { |
|
55 | throw new RuntimeException("No parameter type for '{$parameter->getName()}'"); |
||
56 | } |
||
57 | |||
58 | /** @var ReflectionNamedType $paramType */ |
||
59 | 1 | $paramType = $parameter->getType(); |
|
60 | 1 | $paramTypeName = $paramType->getName(); |
|
61 | 1 | if (!class_exists($paramTypeName) && !interface_exists($paramTypeName)) { |
|
62 | if ($parameter->isDefaultValueAvailable()) { |
||
63 | return $parameter->getDefaultValue(); |
||
64 | } |
||
65 | |||
66 | /** @psalm-suppress PossiblyNullReference */ |
||
67 | throw new RuntimeException("Unable to resolve [$parameter] from {$parameter->getDeclaringClass()->getName()}"); |
||
68 | } |
||
69 | |||
70 | /** @var mixed $mappedClass */ |
||
71 | 1 | $mappedClass = $this->gacelaConfigFile->getMappingInterface($paramTypeName); |
|
72 | 1 | if (is_callable($mappedClass)) { |
|
73 | 1 | return $mappedClass(); |
|
74 | } |
||
75 | |||
76 | 1 | if (is_object($mappedClass)) { |
|
77 | 1 | return $mappedClass; |
|
78 | } |
||
79 | |||
80 | 1 | $reflection = $this->resolveReflectionClass($paramTypeName); |
|
81 | 1 | $constructor = $reflection->getConstructor(); |
|
82 | 1 | if (!$constructor) { |
|
83 | 1 | return $reflection->newInstance(); |
|
84 | } |
||
85 | |||
86 | /** @var list<mixed> $innerDependencies */ |
||
87 | 1 | $innerDependencies = []; |
|
88 | |||
89 | 1 | foreach ($constructor->getParameters() as $constructorParameter) { |
|
90 | 1 | $paramType = $constructorParameter->getType(); |
|
91 | 1 | if ($paramType) { |
|
92 | /** @psalm-suppress MixedAssignment */ |
||
93 | 1 | $innerDependencies[] = $this->resolveDependenciesRecursively($constructorParameter); |
|
94 | } |
||
95 | } |
||
96 | |||
97 | 1 | return $reflection->newInstanceArgs($innerDependencies); |
|
1 ignored issue
–
show
|
|||
98 | } |
||
122 |