Conditions | 10 |
Paths | 10 |
Total Lines | 28 |
Lines | 0 |
Ratio | 0 % |
Tests | 20 |
CRAP Score | 10.0107 |
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 |
||
69 | 24 | public static function ensureArray($value) |
|
70 | { |
||
71 | 24 | switch (gettype($value)) { |
|
72 | 24 | case 'string': |
|
73 | 23 | $return = explode(' ', $value); |
|
74 | 23 | break; |
|
75 | |||
76 | 8 | case 'array': |
|
77 | 8 | case 'double': |
|
78 | 8 | case 'integer': |
|
79 | 2 | $return = array((string) $value); |
|
80 | 2 | break; |
|
81 | 8 | case 'object': |
|
82 | 1 | $return = array(); |
|
83 | 1 | if (method_exists($value, '__toString')) { |
|
84 | $return = array((string) $value); |
||
85 | } |
||
86 | 1 | break; |
|
87 | 8 | case 'boolean': |
|
88 | 8 | case 'resource': |
|
89 | 8 | case 'NULL': |
|
90 | default: |
||
91 | 8 | $return = array(); |
|
92 | 8 | break; |
|
93 | } |
||
94 | |||
95 | 24 | return $return; |
|
96 | } |
||
97 | } |
||
98 |