Passed
Pull Request — master (#79)
by Rustam
02:44
created

EventCollector   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 93.75%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 33
ccs 15
cts 16
cp 0.9375
rs 10
wmc 7

4 Methods

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