Passed
Push — master ( cf37f2...bd53e8 )
by Alexander
02:23
created

EventCollector   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 93.33%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 11
c 1
b 0
f 0
dl 0
loc 32
ccs 14
cts 15
cp 0.9333
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A collectEvent() 0 6 1
A reset() 0 3 1
A getCollected() 0 3 1
A collect() 0 7 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Debug\Collector;
6
7
use Yiisoft\Yii\Console\Event\ApplicationStartup as ConsoleApplicationStartup;
8
use Yiisoft\Yii\Http\Event\ApplicationStartup as HttpApplicationStartup;
9
10
use function get_class;
11
12
final class EventCollector implements EventCollectorInterface
13
{
14
    use CollectorTrait;
15
16
    private array $events = [];
17
18 1
    public function getCollected(): array
19
    {
20 1
        return $this->events;
21
    }
22
23 1
    public function collect(object $event): void
24
    {
25 1
        if (!$event instanceof HttpApplicationStartup && !$event instanceof ConsoleApplicationStartup && !$this->isActive()) {
26
            return;
27
        }
28
29 1
        $this->collectEvent($event);
30 1
    }
31
32 1
    private function collectEvent(object $event): void
33
    {
34 1
        $this->events[] = [
35 1
            'name' => get_class($event),
36 1
            'event' => $event,
37 1
            'time' => microtime(true),
38
        ];
39 1
    }
40
41 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...
42
    {
43 1
        $this->events = [];
44 1
    }
45
}
46