Conditions | 12 |
Paths | 16 |
Total Lines | 38 |
Code Lines | 22 |
Lines | 0 |
Ratio | 0 % |
Tests | 10 |
CRAP Score | 12 |
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 |
||
63 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface |
||
64 | { |
||
65 | 1 | $this->request = $request; |
|
66 | $this->response = $response; |
||
67 | 1 | ||
68 | 1 | $method = $this->getActionMethod($request->getAttribute('route:action', 'process')); |
|
69 | $refl = method_exists($this, $method) ? new \ReflectionMethod($this, $method) : null; |
||
70 | |||
71 | if ($refl === null || !$refl->isPublic() || $refl->isConstructor() || $method === __METHOD__) { |
||
72 | return $this->notFound()->output('Not found')->getResponse(); |
||
73 | } |
||
74 | |||
75 | try { |
||
76 | $args = $this->getFunctionArgs($refl); |
||
77 | } catch (ParameterException $exception) { |
||
78 | return $this->badRequest()->output($exception->getMessage())->getResponse(); |
||
79 | } |
||
80 | |||
81 | $result = $this->guard(new \ReflectionObject($this)); |
||
82 | if ($result !== null) { |
||
83 | return $result; |
||
84 | } |
||
85 | 2 | ||
86 | $result = $this->before(); |
||
1 ignored issue
–
show
|
|||
87 | 2 | if ($result !== null) { |
|
1 ignored issue
–
show
|
|||
88 | 2 | return $result instanceof ResponseInterface ? $result : $this->getResponse(); |
|
89 | } |
||
90 | 2 | ||
91 | 1 | $result = $this->guard($refl); |
|
92 | if ($result !== null) { |
||
93 | return $result; |
||
94 | 2 | } |
|
95 | |||
96 | 2 | $result = [$this, $method](...$args); |
|
97 | |||
98 | $response = $this->after() ?? $result; |
||
1 ignored issue
–
show
|
|||
99 | |||
100 | return $response instanceof ResponseInterface ? $response : $this->getResponse(); |
||
101 | } |
||
103 |