| Conditions | 10 |
| Paths | 9 |
| Total Lines | 47 |
| Code Lines | 24 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 20 |
| CRAP Score | 10.7998 |
| 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 | /** @var ReflectionClass $reflectionClass */ |
||
| 67 | $reflectionClass = $parameter->getDeclaringClass(); |
||
| 68 | throw new RuntimeException("Unable to resolve [$parameter] from {$reflectionClass->getName()}"); |
||
| 69 | } |
||
| 70 | |||
| 71 | /** @var mixed $mappedClass */ |
||
| 72 | 1 | $mappedClass = $this->gacelaConfigFile->getMappingInterface($paramTypeName); |
|
| 73 | 1 | if (is_callable($mappedClass)) { |
|
| 74 | 1 | return $mappedClass(); |
|
| 75 | } |
||
| 76 | |||
| 77 | 1 | if (is_object($mappedClass)) { |
|
| 78 | 1 | return $mappedClass; |
|
| 79 | } |
||
| 80 | |||
| 81 | 1 | $reflection = $this->resolveReflectionClass($paramTypeName); |
|
| 82 | 1 | $constructor = $reflection->getConstructor(); |
|
| 83 | 1 | if (!$constructor) { |
|
| 84 | 1 | return $reflection->newInstance(); |
|
| 85 | } |
||
| 86 | |||
| 87 | /** @var list<mixed> $innerDependencies */ |
||
| 88 | 1 | $innerDependencies = []; |
|
| 89 | |||
| 90 | 1 | foreach ($constructor->getParameters() as $constructorParameter) { |
|
| 91 | 1 | $paramType = $constructorParameter->getType(); |
|
| 92 | 1 | if ($paramType) { |
|
| 93 | /** @psalm-suppress MixedAssignment */ |
||
| 94 | 1 | $innerDependencies[] = $this->resolveDependenciesRecursively($constructorParameter); |
|
| 95 | } |
||
| 96 | } |
||
| 97 | |||
| 98 | 1 | return $reflection->newInstanceArgs($innerDependencies); |
|
|
1 ignored issue
–
show
|
|||
| 99 | } |
||
| 123 |