Passed
Pull Request — master (#102)
by Rustam
02:32
created

EventCollector::collectEvent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 1
rs 10
c 1
b 0
f 0
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
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 WebApplicationStartup && !$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