| Conditions | 12 |
| Paths | 10 |
| Total Lines | 26 |
| Code Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 156 |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 28 | private function renderValue($value) |
||
| 29 | { |
||
| 30 | if ($value === null) { |
||
| 31 | return 'null'; |
||
| 32 | } |
||
| 33 | if (is_bool($value)) { |
||
| 34 | return $value ? 'true' : 'false'; |
||
| 35 | } |
||
| 36 | if (is_array($value)) { |
||
| 37 | if (count($value) === 0) { |
||
| 38 | return '[]'; |
||
| 39 | } |
||
| 40 | $result = '['; |
||
| 41 | foreach ($value as $key => $item) { |
||
| 42 | $result .= "\n"; |
||
| 43 | if (!$item instanceof ArrayItem) { |
||
| 44 | $result .= is_int($key) ? "{$key} => " : "'{$key}' => "; |
||
| 45 | } |
||
| 46 | $result .= $this->renderValue($item) . ','; |
||
| 47 | } |
||
| 48 | return str_replace("\n", "\n ", $result) . "\n]"; |
||
| 49 | } |
||
| 50 | if (!$this->wrapValue || is_int($value) || $value instanceof ArrayItem) { |
||
| 51 | return (string)$value; |
||
| 52 | } |
||
| 53 | return "'" . addslashes((string)$value) . "'"; |
||
| 54 | } |
||
| 56 |