Passed
Push — master ( f7ef7a...65c26d )
by Dmitriy
02:46
created

EventCollector::collect()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 4.5923

Importance

Changes 0
Metric Value
eloc 6
c 0
b 0
f 0
dl 0
loc 11
rs 10
ccs 2
cts 3
cp 0.6667
cc 4
nc 2
nop 2
crap 4.5923
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
class EventCollector implements SummaryCollectorInterface
12
{
13
    use CollectorTrait;
14
15
    private array $events = [];
16
17
    public function getCollected(): array
18
    {
19 1
        return $this->events;
20
    }
21 1
22
    public function collect(object $event, string $line): void
23
    {
24 1
        if (
25
            !$event instanceof HttpApplicationStartup
26
            && !$event instanceof ConsoleApplicationStartup
27
            && !$this->isActive()
28
        ) {
29 1
            return;
30
        }
31
32
        $this->collectEvent($event, $line);
33
    }
34 1
35
    private function collectEvent(object $event, $line): void
36
    {
37 1
        $this->events[] = [
38
            'name' => $event::class,
39 1
            'event' => $event,
40 1
            'file' => (new ReflectionClass($event))->getFileName(),
41
            'line' => $line,
42 1
            'time' => microtime(true),
43
        ];
44 1
    }
45
46
    public function getSummary(): array
47
    {
48 1
        return [
49
            'event' => [
50
                'total' => count($this->events),
51
            ],
52 1
        ];
53
    }
54
55
    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