Conditions | 17 |
Paths | 75 |
Total Lines | 53 |
Code Lines | 32 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
49 | public function __invoke($handler, array $arguments) |
||
50 | { |
||
51 | if (\is_string($handler)) { |
||
52 | if (null !== $this->container && $this->container->has($handler)) { |
||
53 | $handler = $this->container->get($handler); |
||
54 | } elseif (\str_contains($handler, '@')) { |
||
55 | $handler = \explode('@', $handler, 2); |
||
56 | |||
57 | goto maybe_callable; |
||
58 | } elseif (\class_exists($handler)) { |
||
59 | $handlerRef = new \ReflectionClass($handler); |
||
60 | |||
61 | if ($handlerRef->hasMethod('__invoke')) { |
||
62 | $handler = [$handler, '__invoke']; |
||
63 | |||
64 | goto maybe_callable; |
||
65 | } |
||
66 | |||
67 | if (null !== $constructor = $handlerRef->getConstructor()) { |
||
68 | $constructorParameters = $constructor->getParameters(); |
||
69 | |||
70 | goto resolve_handler; |
||
71 | } |
||
72 | |||
73 | return $handlerRef->newInstanceWithoutConstructor(); |
||
74 | } |
||
75 | } |
||
76 | |||
77 | if ((\is_array($handler) && [0, 1] === \array_keys($handler)) && \is_string($handler[0])) { |
||
78 | maybe_callable: |
||
79 | if (null !== $this->container && $this->container->has($handler[0])) { |
||
80 | $handler[0] = $this->container->get($handler[0]); |
||
81 | } elseif (\class_exists($handler[0])) { |
||
82 | $handler[0] = (new \ReflectionClass($handler[0]))->newInstanceArgs(); |
||
83 | } |
||
84 | } |
||
85 | |||
86 | if (\is_callable($handler)) { |
||
87 | $handlerRef = new \ReflectionFunction(\Closure::fromCallable($handler)); |
||
88 | } elseif (\is_object($handler)) { |
||
89 | return $handler; |
||
90 | } else { |
||
91 | throw new InvalidControllerException(\sprintf('Route has an invalid handler type of "%s".', \gettype($handler))); |
||
92 | } |
||
93 | |||
94 | resolve_handler: |
||
95 | $parameters = $this->resolveParameters($constructorParameters ?? $handlerRef->getParameters(), $arguments); |
||
|
|||
96 | |||
97 | if ($handlerRef instanceof \ReflectionFunction) { |
||
98 | return $handlerRef->invokeArgs($parameters); |
||
99 | } |
||
100 | |||
101 | return $handlerRef->newInstanceArgs($parameters); |
||
102 | } |
||
157 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.