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 |
||
29 | public function getController(RpcRequest $request) |
||
30 | { |
||
31 | if (!$controller = $request->attributes->get('_controller')) { |
||
32 | if (null !== $this->logger) { |
||
33 | $this->logger->warning('Unable to look for the controller as the "_controller" parameter is missing.'); |
||
34 | } |
||
35 | |||
36 | return false; |
||
37 | } |
||
38 | |||
39 | if (is_array($controller)) { |
||
40 | return $controller; |
||
41 | } |
||
42 | |||
43 | if (is_object($controller)) { |
||
44 | if (method_exists($controller, '__invoke')) { |
||
45 | return $controller; |
||
46 | } |
||
47 | |||
48 | throw new \InvalidArgumentException(sprintf('Controller "%s" for URI "%s" is not callable.', get_class($controller), $request->getPathInfo())); |
||
|
|||
49 | } |
||
50 | |||
51 | if (false === strpos($controller, ':')) { |
||
52 | if (method_exists($controller, '__invoke')) { |
||
53 | return $this->instantiateController($controller); |
||
54 | } elseif (function_exists($controller)) { |
||
55 | return $controller; |
||
56 | } |
||
57 | } |
||
58 | |||
59 | $callable = $this->createController($controller); |
||
60 | |||
61 | if (!is_callable($callable)) { |
||
62 | throw new \InvalidArgumentException(sprintf('Controller "%s" for URI "%s" is not callable.', $controller, $request->getPathInfo())); |
||
63 | } |
||
64 | |||
65 | return $callable; |
||
66 | } |
||
67 | |||
141 |
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.