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 |
||
64 | 24 | public function ensureArray($value) |
|
65 | { |
||
66 | 24 | switch (gettype($value)) { |
|
67 | 24 | case 'string': |
|
68 | 23 | $return = explode(' ', $value); |
|
69 | 23 | break; |
|
70 | |||
71 | 8 | case 'array': |
|
72 | 8 | case 'double': |
|
73 | 8 | case 'integer': |
|
74 | 2 | $return = array((string) $value); |
|
75 | 2 | break; |
|
76 | 8 | case 'object': |
|
77 | 1 | $return = array(); |
|
78 | 1 | if (method_exists($value, '__toString')) { |
|
79 | $return = array((string) $value); |
||
80 | } |
||
81 | 1 | break; |
|
82 | 8 | case 'boolean': |
|
83 | 8 | case 'resource': |
|
84 | 8 | case 'NULL': |
|
85 | default: |
||
86 | 8 | $return = array(); |
|
87 | 8 | break; |
|
88 | } |
||
89 | |||
90 | 24 | return $return; |
|
91 | } |
||
92 | } |
||
93 |