Passed
Pull Request — master (#434)
by
unknown
14:48
created

CMSDataCollector::reset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
/*
4
 * This file has been created by developers from BitBag.
5
 * Feel free to contact us once you face any issues or want to start
6
 * You can find more information about us on https://bitbag.io and write us
7
 * an email on [email protected].
8
 */
9
10
declare(strict_types=1);
11
12
namespace BitBag\SyliusCmsPlugin\DataCollector;
13
14
use Symfony\Component\HttpFoundation\Request;
15
use Symfony\Component\HttpFoundation\Response;
16
use Symfony\Component\HttpKernel\DataCollector\DataCollector as Collector;
17
use Symfony\Component\HttpKernel\DataCollector\DataCollectorInterface;
18
19
class CMSDataCollector extends Collector implements DataCollectorInterface
20
{
21
    /**
22
     * @var BlockRenderingHistoryInterface
23
     */
24
    private $blockRenderingHistory;
25
26
    /** @var MediaRenderingHistoryInterface */
27
    private $mediaRenderingHistory;
28
29
    /** @var PageRenderingHistoryInterface */
30
    private $pageRenderingHistory;
31
32
    public function __construct(
33
        BlockRenderingHistoryInterface $blockRenderingHistory,
34
        MediaRenderingHistoryInterface $mediaRenderingHistory,
35
        PageRenderingHistoryInterface $pageRenderingHistory
36
    )
37
    {
38
        $this->blockRenderingHistory = $blockRenderingHistory;
39
        $this->mediaRenderingHistory = $mediaRenderingHistory;
40
        $this->pageRenderingHistory = $pageRenderingHistory;
41
    }
42
43
    public function collect(Request $request, Response $response, \Throwable $exception = null): void
44
    {
45
        $this->data = [
46
            'media' => $this->mediaRenderingHistory->getRenderedHistory(),
47
            'block' => $this->blockRenderingHistory->getRenderedHistory(),
48
            'page' => $this->pageRenderingHistory->getRenderedHistory()
49
        ];
50
    }
51
52
    public static function getTemplate(): ?string
53
    {
54
        return "@BitBagSyliusCmsPlugin/CMSDataCollector/block_collector.html.twig";
55
    }
56
57
    public function reset(): void
58
    {
59
        $this->data = [];
60
    }
61
62
    public function getMedia(): array
63
    {
64
        return $this->data['media'];
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->data['media'] could return the type Symfony\Component\VarDumper\Cloner\Data|null which is incompatible with the type-hinted return array. Consider adding an additional type-check to rule them out.
Loading history...
65
    }
66
67
    public function getBlock(): array
68
    {
69
        return $this->data['block'];
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->data['block'] could return the type Symfony\Component\VarDumper\Cloner\Data|null which is incompatible with the type-hinted return array. Consider adding an additional type-check to rule them out.
Loading history...
70
    }
71
72
    public function getPage(): array
73
    {
74
        return $this->data['page'];
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->data['page'] could return the type Symfony\Component\VarDumper\Cloner\Data|null which is incompatible with the type-hinted return array. Consider adding an additional type-check to rule them out.
Loading history...
75
    }
76
77
    public function getName(): string
78
    {
79
        return 'bitbag_sylius_cms_plugin.data_collector.cms';
80
    }
81
}
82