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

ServiceCollector::collect()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 27
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 13
c 1
b 0
f 0
nc 2
nop 9
dl 0
loc 27
rs 9.8333
ccs 5
cts 5
cp 1
crap 2

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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