LogCollector   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 90.91%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
dl 0
loc 48
rs 10
c 1
b 0
f 0
ccs 10
cts 11
cp 0.9091
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A collect() 0 14 2
A getCollected() 0 6 2
A reset() 0 3 1
A getSummary() 0 8 2
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Debug\Collector;
6
7
class LogCollector implements SummaryCollectorInterface
8
{
9
    use CollectorTrait;
10
11
    private array $messages = [];
12
13 2
    public function __construct(
14
        private readonly TimelineCollector $timelineCollector
15 2
    ) {
16
    }
17
18 2
    public function getCollected(): array
19
    {
20 2
        if (!$this->isActive()) {
21
            return [];
22
        }
23
        return $this->messages;
24 2
    }
25 2
26
    public function collect(string $level, mixed $message, array $context, string $line): void
27
    {
28
        if (!$this->isActive()) {
29
            return;
30
        }
31
32
        $this->messages[] = [
33 1
            'time' => microtime(true),
34
            'level' => $level,
35 1
            'message' => $message,
36
            'context' => $context,
37
            'line' => $line,
38 1
        ];
39
        $this->timelineCollector->collect($this, count($this->messages));
40
    }
41
42 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...
43
    {
44
        $this->messages = [];
45
    }
46
47
    public function getSummary(): array
48
    {
49
        if (!$this->isActive()) {
50
            return [];
51
        }
52
        return [
53
            'logger' => [
54
                'total' => count($this->messages),
55
            ],
56
        ];
57
    }
58
}
59