Conditions | 14 |
Paths | 13 |
Total Lines | 43 |
Code Lines | 20 |
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 |
||
58 | protected function normalizeCallable($callable, array $args = []) |
||
59 | { |
||
60 | // invokable object |
||
61 | if (is_object($callable) && method_exists($callable, '__invoke')) { |
||
62 | return $callable; |
||
63 | } |
||
64 | |||
65 | // class::method string |
||
66 | if (is_string($callable)) { |
||
67 | // Split :: |
||
68 | $callable = $this->resolveString($callable); |
||
69 | } |
||
70 | |||
71 | // function string |
||
72 | if (is_string($callable) && function_exists($callable)) { |
||
73 | return $callable; |
||
74 | } |
||
75 | |||
76 | // class string (invokable class) |
||
77 | if (is_string($callable) |
||
78 | && class_exists($callable) |
||
79 | && function_exists($callable . '::__invoke') |
||
80 | ) { |
||
81 | $instance = $this->findInContainer($callable, $args); |
||
82 | if ($instance) { |
||
83 | $callable = $instance; |
||
84 | } |
||
85 | |||
86 | return [$callable, '__invoke']; |
||
87 | } |
||
88 | |||
89 | // callable array with class and method as strings |
||
90 | if (is_array($callable) && is_string($callable[0]) && class_exists($callable[0])) { |
||
91 | $instance = $this->findInContainer($callable[0], $args); |
||
92 | if ($instance) { |
||
93 | $callable[0] = $instance; |
||
94 | } |
||
95 | |||
96 | return $callable; |
||
97 | } |
||
98 | |||
99 | return $callable; |
||
100 | } |
||
101 | |||
116 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.