Passed
Pull Request — master (#225)
by Dmitriy
13:44
created

ServiceCollector   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 25
c 1
b 0
f 0
dl 0
loc 62
rs 10
ccs 10
cts 10
cp 1
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A collect() 0 27 2
A getCollected() 0 6 2
A reset() 0 3 1
A getSummary() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Debug\Collector;
6
7
final class ServiceCollector implements SummaryCollectorInterface
8
{
9
    use CollectorTrait;
10
11
    private array $items = [];
12
13 2
    public function __construct(private TimelineCollector $timelineCollector)
14
    {
15 2
    }
16
17
    public function getCollected(): array
18 7
    {
19
        if (!$this->isActive()) {
20
            return [];
21
        }
22
        return $this->items;
23
    }
24
25
    public function collect(
26
        string $service,
27
        string $class,
28
        string $method,
29 7
        ?array $arguments,
30 5
        $result,
31
        string $status,
32
        ?object $error,
33 2
        float $timeStart,
34
        float $timeEnd
35
    ): void {
36
        if (!$this->isActive()) {
37
            return;
38
        }
39
40
        $this->items[] = [
41
            'service' => $service,
42
            'class' => $class,
43
            'method' => $method,
44
            'arguments' => $arguments,
45
            'result' => $result,
46 1
            'status' => $status,
47
            'error' => $error,
48
            'timeStart' => $timeStart,
49
            'timeEnd' => $timeEnd,
50 1
        ];
51
        $this->timelineCollector->collect($this, count($this->items));
52
    }
53
54
    public function getSummary(): array
55 1
    {
56
        if (!$this->isActive()) {
57 1
            return [];
58
        }
59
        return [
60
            'service' => [
61
                'total' => count($this->items),
62
            ],
63
        ];
64
    }
65
66
    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...
67
    {
68
        $this->items = [];
69
    }
70
}
71