Passed
Push — master ( a4ffc4...615af5 )
by Alexander
03:23
created

EventCollector::collect()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 4.128

Importance

Changes 0
Metric Value
cc 4
eloc 6
c 0
b 0
f 0
nc 2
nop 2
dl 0
loc 11
ccs 4
cts 5
cp 0.8
crap 4.128
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Debug\Collector;
6
7
use JetBrains\PhpStorm\ArrayShape;
8
use Yiisoft\Yii\Console\Event\ApplicationStartup as ConsoleApplicationStartup;
9
use Yiisoft\Yii\Http\Event\ApplicationStartup as HttpApplicationStartup;
10
11
use function get_class;
12
13
final class EventCollector implements EventCollectorInterface, IndexCollectorInterface
14
{
15
    use CollectorTrait;
16
17
    private array $events = [];
18
19 1
    public function getCollected(): array
20
    {
21 1
        return $this->events;
22
    }
23
24 1
    public function collect(object $event, string $line): void
25
    {
26
        if (
27 1
            !$event instanceof HttpApplicationStartup
28
            && !$event instanceof ConsoleApplicationStartup
29 1
            && !$this->isActive()
30
        ) {
31
            return;
32
        }
33
34 1
        $this->collectEvent($event, $line);
35
    }
36
37 1
    private function collectEvent(object $event, $line): void
38
    {
39 1
        $this->events[] = [
40 1
            'name' => get_class($event),
41 1
            'event' => $event,
42 1
            'line' => $line,
43 1
            'time' => microtime(true),
44
        ];
45
    }
46
47 1
    #[ArrayShape(['totalEvents' => 'int'])]
48
    public function getIndexData(): array
49
    {
50
        return [
51 1
            'totalEvents' => count($this->events),
52
        ];
53
    }
54
55 1
    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...
56
    {
57 1
        $this->events = [];
58
    }
59
}
60