View::dumpViewData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
1
<?php
2
3
namespace Facade\FlareClient;
4
5
use Symfony\Component\VarDumper\Cloner\VarCloner;
6
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
7
8
class View
9
{
10
    /** @var string */
11
    private $file;
12
13
    /** @var array */
14
    private $data = [];
15
16
    public function __construct(string $file, array $data = [])
17
    {
18
        $this->file = $file;
19
        $this->data = $data;
20
    }
21
22
    public static function create(string $file, array $data = []): self
23
    {
24
        return new static($file, $data);
25
    }
26
27
    private function dumpViewData($variable): string
28
    {
29
        $cloner = new VarCloner();
30
31
        $dumper = new HtmlDumper();
32
        $dumper->setDumpHeader('');
33
34
        $output = fopen('php://memory', 'r+b');
35
36
        $dumper->dump($cloner->cloneVar($variable)->withMaxDepth(1), $output, [
37
            'maxDepth' => 1,
38
            'maxStringLength' => 160,
39
        ]);
40
41
        return stream_get_contents($output, -1, 0);
42
    }
43
44
    public function toArray()
45
    {
46
        return [
47
            'file' => $this->file,
48
            'data' => array_map([$this, 'dumpViewData'], $this->data),
49
        ];
50
    }
51
}
52