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

LogCollector   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 93.33%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 36
ccs 14
cts 15
cp 0.9333
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getCollected() 0 3 1
A collect() 0 12 2
A getIndexData() 0 5 1
A reset() 0 3 1
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