View   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 44
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 3

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A create() 0 4 1
A dumpViewData() 0 16 1
A toArray() 0 7 1
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