| Conditions | 12 |
| Paths | 24 |
| Total Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 25 |
| CRAP Score | 12.1769 |
| 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 |
||
| 62 | 24 | public function ensureArray($value) |
|
| 63 | { |
||
| 64 | 24 | $return = null; |
|
| 65 | |||
| 66 | 24 | switch (gettype($value)) { |
|
| 67 | 24 | case 'string': |
|
| 68 | 23 | $return = $value; |
|
| 69 | 23 | break; |
|
| 70 | 8 | case 'integer': |
|
| 71 | 8 | case 'double': |
|
| 72 | 2 | $return = (string) $value; |
|
| 73 | 2 | break; |
|
| 74 | 8 | case 'object': |
|
| 75 | 1 | if (method_exists($value, '__toString')) { |
|
| 76 | $return = (string) $value; |
||
| 77 | } |
||
| 78 | 1 | break; |
|
| 79 | 8 | case 'array': |
|
| 80 | 8 | case 'boolean': |
|
| 81 | 1 | if (true === $value) { |
|
| 82 | 1 | $return = ''; |
|
| 83 | } |
||
| 84 | 1 | break; |
|
| 85 | 8 | case 'resource': |
|
| 86 | 8 | case 'NULL': |
|
| 87 | 8 | $return = null; |
|
| 88 | 8 | break; |
|
| 89 | default: |
||
| 90 | $return = null; |
||
| 91 | break; |
||
| 92 | } |
||
| 93 | |||
| 94 | 24 | return $return === null ? |
|
| 95 | 8 | []: |
|
| 96 | 24 | explode(' ', preg_replace('!\s+!', ' ', trim($return))); |
|
| 97 | } |
||
| 98 | } |
||
| 99 |