Completed
Push — master ( 9a9f60...45932f )
by Michał
02:53
created

VarDumper::__invoke()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.2
c 0
b 0
f 0
cc 4
eloc 8
nc 4
nop 1
1
<?php namespace nyx\diagnostics\debug\dumpers;
2
3
// Vendor dependencies
4
use Symfony\Component\VarDumper as base;
5
6
// Internal dependencies
7
use nyx\diagnostics\debug\interfaces;
8
9
/**
10
 * Symfony VarDumper Dumper
11
 *
12
 * A bridge allowing to use Symfony's VarDumper as a Dumper within the Debug subcomponent. Check out VarDumper
13
 * itself in Symfony's docs {@see http://symfony.com/doc/current/components/var_dumper/index.html}.
14
 *
15
 * Requires:
16
 * - Package: symfony/var-dumper (available as suggestion for nyx/diagnostics within Composer)
17
 *
18
 * @version     0.1.0
19
 * @author      Michal Chojnacki <[email protected]>
20
 * @copyright   2012-2017 Nyx Dev Team
21
 * @link        https://github.com/unyx/nyx
22
 */
23
class VarDumper implements interfaces\Dumper
24
{
25
    /**
26
     * @var callable    The built proxy callable.
27
     */
28
    private $handler;
29
30
    /**
31
     * {@inheritDoc}
32
     */
33
    public function __invoke(...$vars)
34
    {
35
        if (!isset($this->handler)) {
36
            $cloner = new base\Cloner\VarCloner;
37
            $dumper = 'cli' === PHP_SAPI ? new base\Dumper\CliDumper : new base\Dumper\HtmlDumper;
38
39
            $this->handler = function($var) use ($cloner, $dumper) {
40
                $dumper->dump($cloner->cloneVar($var));
41
            };
42
        }
43
44
        // VarDumper isn't variadic so we need to adapt.
45
        foreach ($vars as $var) {
46
            call_user_func($this->handler, $var);
47
        }
48
    }
49
}
50