Passed
Push — master ( 755731...71ac2a )
by Dmitriy
02:36
created

LogCollector::collect()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 9
c 0
b 0
f 0
nc 2
nop 4
dl 0
loc 14
rs 9.9666
ccs 4
cts 4
cp 1
crap 2
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(private TimelineCollector $timelineCollector, )
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces before closing parenthesis; 1 found
Loading history...
14
    {
15 2
    }
16
17
    public function getCollected(): array
18 2
    {
19
        if (!$this->isActive()) {
20 2
            return [];
21
        }
22
        return $this->messages;
23
    }
24 2
25 2
    public function collect(string $level, $message, array $context, string $line): void
26
    {
27
        if (!$this->isActive()) {
28
            return;
29
        }
30
31
        $this->messages[] = [
32
            'time' => microtime(true),
33 1
            'level' => $level,
34
            'message' => $message,
35 1
            'context' => $context,
36
            'line' => $line,
37
        ];
38 1
        $this->timelineCollector->collect($this, count($this->messages));
39
    }
40
41
    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...
42 1
    {
43
        $this->messages = [];
44
    }
45
46
    public function getSummary(): array
47
    {
48
        if (!$this->isActive()) {
49
            return [];
50
        }
51
        return [
52
            'logger' => [
53
                'total' => count($this->messages),
54
            ],
55
        ];
56
    }
57
}
58