Passed
Pull Request — master (#434)
by
unknown
07:43 queued 02:16
created

CMSDataCollector::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 8
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
        $this->data = [
48
            'media' => $this->mediaRenderingHistory->getRenderedHistory(),
49
            'block' => $this->blockRenderingHistory->getRenderedHistory(),
50
            'page' => $this->pageRenderingHistory->getRenderedHistory(),
51
        ];
52
    }
53
54
    public static function getTemplate(): ?string
55
    {
56
        return '@BitBagSyliusCmsPlugin/CMSDataCollector/block_collector.html.twig';
57
    }
58
59
    public function reset(): void
60
    {
61
        $this->data = [];
62
    }
63
64
    public function getMedia(): array
65
    {
66
        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...
67
    }
68
69
    public function getBlock(): array
70
    {
71
        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...
72
    }
73
74
    public function getPage(): array
75
    {
76
        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...
77
    }
78
79
    public function getName(): string
80
    {
81
        return 'bitbag_sylius_cms_plugin.data_collector.cms';
82
    }
83
}
84