Passed
Pull Request — master (#434)
by
unknown
05:11
created

CMSDataCollector::getPage()   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
    /** @var BlockRenderingEventRecorderInterface */
22
    private $blockRenderingHistory;
23
24
    /** @var MediaRenderingEventRecorderInterface */
25
    private $mediaRenderingHistory;
26
27
    /** @var PageRenderingEventRecorderInterface */
28
    private $pageRenderingHistory;
29
30
    public function __construct(
31
        BlockRenderingEventRecorderInterface $blockRenderingHistory,
32
        MediaRenderingEventRecorderInterface $mediaRenderingHistory,
33
        PageRenderingEventRecorderInterface $pageRenderingHistory
34
    ) {
35
        $this->blockRenderingHistory = $blockRenderingHistory;
36
        $this->mediaRenderingHistory = $mediaRenderingHistory;
37
        $this->pageRenderingHistory = $pageRenderingHistory;
38
    }
39
40
    public function collect(
41
        Request $request,
42
        Response $response,
43
        \Throwable $exception = null
44
    ): void {
45
        $this->data = [
46
            'media' => $this->mediaRenderingHistory->getRecordedEvents(),
47
            'block' => $this->blockRenderingHistory->getRecordedEvents(),
48
            'page' => $this->pageRenderingHistory->getRecordedEvents(),
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