Completed
Push — master ( 52cd2c...047880 )
by Kamil
47:26 queued 26:32
created

TemplateBlockRenderingHistory   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 47
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A startRenderingEvent() 0 4 1
A startRenderingBlock() 0 4 1
A stopRenderingBlock() 0 7 1
A stopRenderingEvent() 0 7 1
A getRenderedEvents() 0 4 1
A reset() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Sylius\Bundle\UiBundle\DataCollector;
15
16
use Sylius\Bundle\UiBundle\Registry\TemplateBlock;
17
18
/**
19
 * @internal
20
 */
21
final class TemplateBlockRenderingHistory
22
{
23
    /** @psalm-var list<array{name: string, start: float, stop: float, time: float, blocks: list<array{definition: TemplateBlock, start: float, stop: float, time: float}>}> */
24
    private $renderedEvents = [];
25
26
    /** @psalm-var array{name: string, start: float, stop?: float, time?: float, blocks: list<array{definition: TemplateBlock, start: float, stop: float, time: float}>} */
27
    private $currentlyRenderedEvent = [];
28
29
    /** @psalm-var array{definition: TemplateBlock, start: float, stop?: float, time?: float} */
30
    private $currentlyRenderedBlock = [];
31
32
    public function startRenderingEvent(string $eventName, array $context): void
0 ignored issues
show
Unused Code introduced by
The parameter $context is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
33
    {
34
        $this->currentlyRenderedEvent = ['name' => $eventName, 'start' => microtime(true), 'blocks' => []];
35
    }
36
37
    public function startRenderingBlock(string $eventName, TemplateBlock $templateBlock, array $context): void
0 ignored issues
show
Unused Code introduced by
The parameter $eventName is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $context is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
38
    {
39
        $this->currentlyRenderedBlock = ['definition' => $templateBlock, 'start' => microtime(true)];
40
    }
41
42
    public function stopRenderingBlock(string $eventName, TemplateBlock $templateBlock, array $context): void
0 ignored issues
show
Unused Code introduced by
The parameter $eventName is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $templateBlock is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $context is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
43
    {
44
        $this->currentlyRenderedBlock['stop'] = microtime(true);
45
        $this->currentlyRenderedBlock['time'] = $this->currentlyRenderedBlock['stop'] - $this->currentlyRenderedBlock['start'];
46
        $this->currentlyRenderedEvent['blocks'][] = $this->currentlyRenderedBlock;
47
        $this->currentlyRenderedBlock = [];
48
    }
49
50
    public function stopRenderingEvent(string $eventName, array $context): void
0 ignored issues
show
Unused Code introduced by
The parameter $eventName is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $context is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
51
    {
52
        $this->currentlyRenderedEvent['stop'] = microtime(true);
53
        $this->currentlyRenderedEvent['time'] = $this->currentlyRenderedEvent['stop'] - $this->currentlyRenderedEvent['start'];
54
        $this->renderedEvents[] = $this->currentlyRenderedEvent;
55
        $this->currentlyRenderedEvent = [];
56
    }
57
58
    public function getRenderedEvents(): array
59
    {
60
        return $this->renderedEvents;
61
    }
62
63
    public function reset(): void
64
    {
65
        $this->renderedEvents = $this->currentlyRenderedEvent = $this->currentlyRenderedBlock = [];
66
    }
67
}
68