| Conditions | 12 |
| Paths | 9 |
| Total Lines | 19 |
| Code Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 12 |
| CRAP Score | 12.4202 |
| Changes | 2 | ||
| 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 |
||
| 14 | 12 | public static function render($value, bool $wrapValue = true, int $indentLevel = 0): string |
|
| 15 | { |
||
| 16 | 12 | switch (true) { |
|
| 17 | case $value === null: |
||
| 18 | return 'null'; |
||
| 19 | 12 | case is_bool($value): |
|
| 20 | 6 | return $value ? 'true' : 'false'; |
|
| 21 | 12 | case is_array($value): |
|
| 22 | 12 | return ArrayRenderer::render($value, $indentLevel); |
|
| 23 | 12 | case $value instanceof ExporterItem: |
|
| 24 | 12 | return $value->toString(); |
|
| 25 | 12 | case !$wrapValue || is_int($value): |
|
| 26 | 6 | return (string)$value; |
|
| 27 | 12 | case \is_string($value) && \strpos($value, '\\') !== false && \class_exists($value): |
|
| 28 | 12 | return "$value::class"; |
|
| 29 | case is_string($value): |
||
| 30 | return "'" . addslashes($value) . "'"; |
||
| 31 | default: |
||
| 32 | return "unserialize('" . addslashes(serialize($value)) . "')"; |
||
| 33 | } |
||
| 36 |