| 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 | 24 | public function ensureArray($value) |
|
| 65 | { |
||
| 66 | 24 | $return = null; |
|
| 67 | |||
| 68 | 24 | switch (gettype($value)) { |
|
| 69 | 24 | case 'array': |
|
| 70 | 23 | return $value; |
|
| 71 | 23 | case 'string': |
|
| 72 | 21 | $return = $value; |
|
| 73 | 21 | break; |
|
| 74 | 10 | case 'integer': |
|
| 75 | 9 | case 'double': |
|
| 76 | 2 | $return = (string) $value; |
|
| 77 | 2 | break; |
|
| 78 | 9 | case 'object': |
|
| 79 | 1 | if (method_exists($value, '__toString')) { |
|
| 80 | $return = (string) $value; |
||
| 81 | } |
||
| 82 | 1 | break; |
|
| 83 | 9 | case 'boolean': |
|
| 84 | 1 | if (true === $value) { |
|
| 85 | 1 | $return = ''; |
|
| 86 | } |
||
| 87 | 1 | break; |
|
| 88 | } |
||
| 89 | |||
| 90 | 23 | return $return === null ? |
|
| 91 | 9 | []: |
|
| 92 | 23 | explode(' ', preg_replace('!\s+!', ' ', trim(addcslashes($return, '\"')))); |
|
| 93 | } |
||
| 94 | } |
||
| 95 |