Completed
Push — master ( 755ea5...1d1b4c )
by Marcel
20s queued 10s
created

Dumper::createVarCloner()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace BeyondCode\DumpServer;
4
5
use Symfony\Component\VarDumper\Cloner\VarCloner;
6
use Symfony\Component\VarDumper\Dumper\CliDumper;
7
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
8
use Symfony\Component\VarDumper\Server\Connection;
9
10
class Dumper
11
{
12
    /**
13
     * The connection.
14
     *
15
     * @var \Symfony\Component\VarDumper\Server\Connection|null
16
     */
17
    private $connection;
18
19
    /**
20
     * Dumper constructor.
21
     *
22
     * @param  \Symfony\Component\VarDumper\Server\Connection|null  $connection
23
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
24
     */
25
    public function __construct(Connection $connection = null)
26
    {
27
        $this->connection = $connection;
28
    }
29
30
    /**
31
     * Dump a value with elegance.
32
     *
33
     * @param  mixed  $value
34
     * @return void
35
     */
36
    public function dump($value)
37
    {
38
        if (class_exists(CliDumper::class)) {
39
            $data = $this->createVarCloner()->cloneVar($value);
40
41
            if ($this->connection === null || $this->connection->write($data) === false) {
42
                $dumper = in_array(PHP_SAPI, ['cli', 'phpdbg']) ? new CliDumper : new HtmlDumper;
43
                $dumper->dump($data);
44
            }
45
        } else {
46
            var_dump($value);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($value); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
47
        }
48
    }
49
50
    /**
51
     * @return VarCloner
52
     */
53
    protected function createVarCloner(): VarCloner
54
    {
55
        return new VarCloner();
56
    }
57
}
58