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

EventCollector::collect()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 4.128

Importance

Changes 0
Metric Value
cc 4
eloc 4
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 8
ccs 4
cts 5
cp 0.8
crap 4.128
rs 10
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