| Conditions | 13 |
| Paths | 11 |
| Total Lines | 29 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 40 | private function renderValue($value): string |
||
| 41 | { |
||
| 42 | if ($value === null) { |
||
| 43 | return 'null'; |
||
| 44 | } |
||
| 45 | if (is_bool($value)) { |
||
| 46 | return $value ? 'true' : 'false'; |
||
| 47 | } |
||
| 48 | if (is_array($value)) { |
||
| 49 | if (count($value) === 0) { |
||
| 50 | return '[]'; |
||
| 51 | } |
||
| 52 | $result = '['; |
||
| 53 | foreach ($value as $key => $item) { |
||
| 54 | $result .= "\n"; |
||
| 55 | if (!$item instanceof ArrayItemRenderer) { |
||
| 56 | $result .= is_int($key) ? "{$key} => " : "'{$key}' => "; |
||
| 57 | } |
||
| 58 | $result .= $this->renderValue($item) . ','; |
||
| 59 | } |
||
| 60 | return str_replace("\n", "\n ", $result) . "\n]"; |
||
| 61 | } |
||
| 62 | if (!$this->wrapValue || is_int($value) || $value instanceof ArrayItemRenderer) { |
||
| 63 | return (string)$value; |
||
| 64 | } |
||
| 65 | if (is_string($value)) { |
||
| 66 | return "'" . addslashes($value) . "'"; |
||
| 67 | } |
||
| 68 | return "unserialize('" . addslashes(serialize($value)) . "')"; |
||
| 69 | } |
||
| 71 |