Passed
Pull Request — master (#434)
by
unknown
12:21 queued 07:50
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
    /**
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
        $this->blockRenderingHistory = $blockRenderingHistory;
38
        $this->mediaRenderingHistory = $mediaRenderingHistory;
39
        $this->pageRenderingHistory = $pageRenderingHistory;
40
    }
41
42
    public function collect(
43
        Request $request,
44
        Response $response,
45
        \Throwable $exception = null
46
    ): void
47
    {
48
        $this->data = [
49
            'media' => $this->mediaRenderingHistory->getRenderedHistory(),
50
            'block' => $this->blockRenderingHistory->getRenderedHistory(),
51
            'page' => $this->pageRenderingHistory->getRenderedHistory()
52
        ];
53
    }
54
55
    public static function getTemplate(): ?string
56
    {
57
        return '@BitBagSyliusCmsPlugin/CMSDataCollector/block_collector.html.twig';
58
    }
59
60
    public function reset(): void
61
    {
62
        $this->data = [];
63
    }
64
65
    public function getMedia(): array
66
    {
67
        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...
68
    }
69
70
    public function getBlock(): array
71
    {
72
        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...
73
    }
74
75
    public function getPage(): array
76
    {
77
        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...
78
    }
79
80
    public function getName(): string
81
    {
82
        return 'bitbag_sylius_cms_plugin.data_collector.cms';
83
    }
84
}
85