Conditions | 10 |
Paths | 17 |
Total Lines | 30 |
Lines | 0 |
Ratio | 0 % |
Tests | 22 |
CRAP Score | 10.0082 |
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 |
||
64 | 27 | protected function ensureArray($value) |
|
65 | { |
||
66 | 27 | $return = null; |
|
67 | |||
68 | 27 | switch (gettype($value)) { |
|
69 | 27 | case 'array': |
|
70 | 23 | return $value; |
|
71 | 26 | case 'string': |
|
72 | 21 | $return = $value; |
|
73 | 21 | break; |
|
74 | 15 | case 'integer': |
|
75 | 14 | case 'double': |
|
76 | 2 | $return = (string) $value; |
|
77 | 2 | break; |
|
78 | 14 | case 'object': |
|
79 | 1 | if (method_exists($value, '__toString')) { |
|
80 | $return = (string) $value; |
||
81 | } |
||
82 | 1 | break; |
|
83 | 14 | case 'boolean': |
|
84 | 1 | if (true === $value) { |
|
85 | 1 | $return = ''; |
|
86 | } |
||
87 | 1 | break; |
|
88 | } |
||
89 | |||
90 | 26 | return null === $return ? |
|
91 | 14 | []: |
|
92 | 26 | explode(' ', preg_replace('!\s+!', ' ', trim(addcslashes($return, '\"')))); |
|
93 | } |
||
94 | } |
||
95 |