| Conditions | 16 |
| Paths | 56 |
| Total Lines | 44 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 48 | public function __invoke($handler, array $arguments) |
||
| 49 | { |
||
| 50 | if (\is_string($handler)) { |
||
| 51 | if (null !== $this->container && $this->container->has($handler)) { |
||
| 52 | $handler = $this->container->get($handler); |
||
| 53 | } elseif (\str_contains($handler, '@')) { |
||
| 54 | $handler = \explode('@', $handler, 2); |
||
| 55 | |||
| 56 | goto maybe_callable; |
||
| 57 | } elseif (\class_exists($handler)) { |
||
| 58 | $handlerRef = new \ReflectionClass($handler); |
||
| 59 | |||
| 60 | if ($handlerRef->hasMethod('__invoke')) { |
||
| 61 | $handler = [$handler, '__invoke']; |
||
| 62 | |||
| 63 | goto maybe_callable; |
||
| 64 | } |
||
| 65 | |||
| 66 | if (null === $constructor = $handlerRef->getConstructor()) { |
||
| 67 | return $handlerRef->newInstanceWithoutConstructor(); |
||
| 68 | } |
||
| 69 | |||
| 70 | return $handlerRef->newInstanceArgs($this->resolveParameters($constructor->getParameters(), $arguments)); |
||
| 71 | } |
||
| 72 | } |
||
| 73 | |||
| 74 | if ((\is_array($handler) && [0, 1] === \array_keys($handler)) && \is_string($handler[0])) { |
||
| 75 | maybe_callable: |
||
| 76 | if (null !== $this->container && $this->container->has($handler[0])) { |
||
| 77 | $handler[0] = $this->container->get($handler[0]); |
||
| 78 | } elseif (\class_exists($handler[0])) { |
||
| 79 | $handler[0] = (new \ReflectionClass($handler[0]))->newInstanceArgs([]); |
||
| 80 | } |
||
| 81 | } |
||
| 82 | |||
| 83 | if (\is_callable($handler)) { |
||
| 84 | $handlerRef = new \ReflectionFunction(\Closure::fromCallable($handler)); |
||
| 85 | } elseif (\is_object($handler)) { |
||
| 86 | return $handler; |
||
| 87 | } else { |
||
| 88 | throw new InvalidControllerException(\sprintf('Route has an invalid handler type of "%s".', \gettype($handler))); |
||
| 89 | } |
||
| 90 | |||
| 91 | return $handlerRef->invokeArgs($this->resolveParameters($handlerRef->getParameters(), $arguments)); |
||
| 92 | } |
||
| 147 |