| Conditions | 10 |
| Paths | 33 |
| Total Lines | 36 |
| Code Lines | 19 |
| 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 |
||
| 48 | public function __construct(Context $context, Route $route) |
||
| 49 | { |
||
| 50 | if (!is_subclass_of($route->getControllerClass(), ControllerInterface::class)) { |
||
|
|
|||
| 51 | throw new InvalidControllerException; |
||
| 52 | } |
||
| 53 | |||
| 54 | $this->controller_class = $route->getControllerClass(); |
||
| 55 | |||
| 56 | try { |
||
| 57 | |||
| 58 | $reflection = new \ReflectionClass($this->controller_class); |
||
| 59 | |||
| 60 | foreach ($reflection->getConstructor()->getParameters() as $parameter) { |
||
| 61 | |||
| 62 | if ($parameter->getClass() === null) { |
||
| 63 | |||
| 64 | if (!$parameter->isArray()) { |
||
| 65 | $this->parameters[] = $parameter->isDefaultValueAvailable() ? $parameter->getDefaultValue() : null; |
||
| 66 | } elseif ($parameter->getName() == 'parameters') { |
||
| 67 | $this->parameters[] = $route->getParameters(); |
||
| 68 | } elseif ($parameter->getName() == 'arguments') { |
||
| 69 | $this->parameters[] = $route->getArguments(); |
||
| 70 | } else { |
||
| 71 | $this->parameters[] = $parameter->isDefaultValueAvailable() ? $parameter->getDefaultValue() : []; |
||
| 72 | } |
||
| 73 | |||
| 74 | } else { |
||
| 75 | $this->parameters[] = $context->getSingletons()->get($parameter->getClass()->getName()); |
||
| 76 | } |
||
| 77 | |||
| 78 | } |
||
| 79 | |||
| 80 | } catch (\ReflectionException $e) { |
||
| 81 | // The contructor isn't defined |
||
| 82 | } |
||
| 83 | } |
||
| 84 | |||
| 90 |