Conditions | 10 |
Paths | 10 |
Total Lines | 25 |
Code Lines | 18 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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 |
||
86 | protected static function prepareParameter($parameter) |
||
87 | { |
||
88 | if ($parameter instanceof ParameterInterface) { |
||
89 | return self::prepareParameter($parameter->getValue()); |
||
90 | } |
||
91 | |||
92 | switch (gettype($parameter)) { |
||
93 | case "boolean": |
||
94 | return $parameter ? 'true' : 'false'; |
||
95 | case "integer": |
||
96 | return $parameter + 0; |
||
97 | case "NULL": |
||
98 | return 'NULL'; |
||
99 | case "double": |
||
100 | return sprintf('%F', $parameter); |
||
101 | case "string": |
||
102 | return "'" . addcslashes($parameter, "'") . "'"; |
||
103 | case 'object': |
||
104 | if (method_exists($parameter, '__toString')) { |
||
105 | return "'" . addcslashes((string)$parameter, "'") . "'"; |
||
106 | } |
||
107 | } |
||
108 | |||
109 | return "[UNRESOLVED]"; |
||
110 | } |
||
111 | } |