Passed
Push — master ( 755731...71ac2a )
by Dmitriy
02:36
created

EventCollector::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 2
rs 10
ccs 0
cts 0
cp 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Debug\Collector;
6
7
use ReflectionClass;
8
use Yiisoft\Yii\Console\Event\ApplicationStartup as ConsoleApplicationStartup;
9
use Yiisoft\Yii\Http\Event\ApplicationStartup as HttpApplicationStartup;
10
11
final class EventCollector implements SummaryCollectorInterface
12
{
13
    use CollectorTrait;
14
15
    private array $events = [];
16
17
    public function __construct(private TimelineCollector $timelineCollector)
18
    {
19 1
    }
20
21 1
    public function getCollected(): array
22
    {
23
        if (!$this->isActive()) {
24 1
            return [];
25
        }
26
        return $this->events;
27
    }
28
29 1
    public function collect(object $event, string $line): void
30
    {
31
        if (
32
            !$event instanceof HttpApplicationStartup
33
            && !$event instanceof ConsoleApplicationStartup
34 1
            && !$this->isActive()
35
        ) {
36
            return;
37 1
        }
38
39 1
        $this->events[] = [
40 1
            'name' => $event::class,
41
            'event' => $event,
42 1
            'file' => (new ReflectionClass($event))->getFileName(),
43
            'line' => $line,
44 1
            'time' => microtime(true),
45
        ];
46
        $this->timelineCollector->collect($this, spl_object_id($event), $event::class);
47
    }
48 1
49
    public function getSummary(): array
50
    {
51
        if (!$this->isActive()) {
52 1
            return [];
53
        }
54
        return [
55
            'event' => [
56
                'total' => count($this->events),
57 1
            ],
58
        ];
59 1
    }
60
61
    private function reset(): void
0 ignored issues
show
Unused Code introduced by
The method reset() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
62
    {
63
        $this->events = [];
64
    }
65
}
66