Passed
Push — master ( a4ffc4...615af5 )
by Alexander
03:23
created

LogCollector::collect()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2.0054

Importance

Changes 0
Metric Value
cc 2
eloc 8
c 0
b 0
f 0
nc 2
nop 4
dl 0
loc 12
ccs 8
cts 9
cp 0.8889
crap 2.0054
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Debug\Collector;
6
7
use JetBrains\PhpStorm\ArrayShape;
8
9
final class LogCollector implements LogCollectorInterface, IndexCollectorInterface
10
{
11
    use CollectorTrait;
12
13
    private array $messages = [];
14
15 2
    public function getCollected(): array
16
    {
17 2
        return $this->messages;
18
    }
19
20 2
    public function collect(string $level, $message, array $context, string $line): void
21
    {
22 2
        if (!$this->isActive()) {
23
            return;
24
        }
25
26 2
        $this->messages[] = [
27 2
            'time' => microtime(true),
28 2
            'level' => $level,
29 2
            'message' => $message,
30 2
            'context' => $context,
31 2
            'line' => $line,
32
        ];
33
    }
34
35 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...
36
    {
37 1
        $this->messages = [];
38
    }
39
40 1
    #[ArrayShape(['totalLogs' => 'int'])]
41
    public function getIndexData(): array
42
    {
43
        return [
44 1
            'totalLogs' => count($this->messages),
45
        ];
46
    }
47
}
48