Passed
Pull Request — master (#114)
by Alexander
03:04 queued 17s
created

LogCollector   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 93.75%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A collect() 0 11 2
A getCollected() 0 3 1
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): 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
        ];
32 2
    }
33
34 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...
35
    {
36 1
        $this->messages = [];
37 1
    }
38
39 1
    #[ArrayShape(['totalLogs' => 'int'])]
40
    public function getIndexData(): array
41
    {
42
        return [
43 1
            'totalLogs' => count($this->messages),
44
        ];
45
    }
46
}
47