LogCollector::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
nc 1
nop 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
ccs 2
cts 2
cp 1
crap 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