Passed
Push — 1.x ( a9995e...5c2b79 )
by Aleksei
12:31
created

ValueRenderer::render()   C

Complexity

Conditions 12
Paths 9

Size

Total Lines 19
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 12.4202

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 19
ccs 12
cts 14
cp 0.8571
rs 6.9666
cc 12
nc 9
nop 3
crap 12.4202

How to fix   Complexity   

Long Method

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:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cycle\Schema\Renderer\PhpFileRenderer\Exporter\Rendering;
6
7
use Cycle\Schema\Renderer\PhpFileRenderer\Exporter\ExporterItem;
8
9
final class ValueRenderer
10
{
11
    /**
12
     * @param mixed $value
13
     */
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
        }
34
    }
35
}
36