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

ServiceCollector::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

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