Passed
Pull Request — master (#155)
by Wilmer
12:10 queued 09:41
created

EventCollector   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 93.33%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 19
c 1
b 0
f 0
dl 0
loc 47
ccs 14
cts 15
cp 0.9333
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getCollected() 0 3 1
A collectEvent() 0 8 1
A getIndexData() 0 5 1
A reset() 0 3 1
A collect() 0 11 4
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
use function get_class;
12
13
class EventCollector implements CollectorInterface, 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
            !$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
            'event' => $event,
42 1
            'file' => (new ReflectionClass($event))->getFileName(),
43
            'line' => $line,
44 1
            'time' => microtime(true),
45
        ];
46
    }
47
48 1
    public function getIndexData(): array
49
    {
50
        return [
51
            'event' => [
52 1
                'total' => count($this->events),
53
            ],
54
        ];
55
    }
56
57 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...
58
    {
59 1
        $this->events = [];
60
    }
61
}
62