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

LogCollector   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 90.91%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 47
rs 10
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 2 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(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