Passed
Push — master ( f7ef7a...65c26d )
by Dmitriy
02:46
created

ServiceCollector::collect()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 25
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 12
c 1
b 0
f 0
nc 2
nop 9
dl 0
loc 25
ccs 4
cts 4
cp 1
crap 2
rs 9.8666

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 getCollected(): array
14
    {
15 2
        return $this->items;
16
    }
17
18 7
    public function collect(
19
        string $service,
20
        string $class,
21
        string $method,
22
        ?array $arguments,
23
        $result,
24
        string $status,
25
        ?object $error,
26
        float $timeStart,
27
        float $timeEnd
28
    ): void {
29 7
        if (!$this->isActive()) {
30 5
            return;
31
        }
32
33 2
        $this->items[] = [
34
            'service' => $service,
35
            'class' => $class,
36
            'method' => $method,
37
            'arguments' => $arguments,
38
            'result' => $result,
39
            'status' => $status,
40
            'error' => $error,
41
            'timeStart' => $timeStart,
42
            'timeEnd' => $timeEnd,
43
        ];
44
    }
45
46 1
    public function getSummary(): array
47
    {
48
        return [
49
            'service' => [
50 1
                'total' => count($this->items),
51
            ],
52
        ];
53
    }
54
55 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...
56
    {
57 1
        $this->items = [];
58
    }
59
}
60