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

EventCollector   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 92.86%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 20
c 1
b 0
f 0
dl 0
loc 47
rs 10
ccs 13
cts 14
cp 0.9286

5 Methods

Rating   Name   Duplication   Size   Complexity  
A collectEvent() 0 8 1
A reset() 0 3 1
A getCollected() 0 3 1
A collect() 0 11 4
A getSummary() 0 5 1
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