Conditions | 10 |
Paths | 11 |
Total Lines | 38 |
Code Lines | 20 |
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 |
||
17 | public function getController(JsonRpcRequest $request) |
||
18 | { |
||
19 | if (!$controller = $request->attributes->get('_controller')) { |
||
20 | if (null !== $this->logger) { |
||
21 | $this->logger->warning('Unable to look for the controller as the "_controller" parameter is missing.'); |
||
22 | } |
||
23 | |||
24 | return false; |
||
25 | } |
||
26 | |||
27 | if (is_array($controller)) { |
||
28 | return $controller; |
||
29 | } |
||
30 | |||
31 | if (is_object($controller)) { |
||
32 | if (method_exists($controller, '__invoke')) { |
||
33 | return $controller; |
||
34 | } |
||
35 | |||
36 | throw new \InvalidArgumentException(sprintf('Controller "%s" for URI "%s" is not callable.', get_class($controller), $request->getPathInfo())); |
||
|
|||
37 | } |
||
38 | |||
39 | if (false === strpos($controller, ':')) { |
||
40 | if (method_exists($controller, '__invoke')) { |
||
41 | return $this->instantiateController($controller); |
||
42 | } elseif (function_exists($controller)) { |
||
43 | return $controller; |
||
44 | } |
||
45 | } |
||
46 | |||
47 | $callable = $this->createController($controller); |
||
48 | |||
49 | if (!is_callable($callable)) { |
||
50 | throw new \InvalidArgumentException(sprintf('Controller "%s" for URI "%s" is not callable.', $controller, $request->getPathInfo())); |
||
51 | } |
||
52 | |||
53 | return $callable; |
||
54 | } |
||
55 | |||
123 |
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.