Passed
Pull Request — master (#114)
by Rustam
02:28
created

ServiceCollector::collect()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 25
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
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 13
cts 13
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
use JetBrains\PhpStorm\ArrayShape;
8
9
final class ServiceCollector implements ServiceCollectorInterface, IndexCollectorInterface
10
{
11
    use CollectorTrait;
12
13
    private array $items = [];
14
15 2
    public function getCollected(): array
16
    {
17 2
        return $this->items;
18
    }
19
20 7
    public function collect(
21
        string $service,
22
        string $class,
23
        string $method,
24
        ?array $arguments,
25
        $result,
26
        string $status,
27
        ?object $error,
28
        float $timeStart,
29
        float $timeEnd
30
    ): void {
31 7
        if (!$this->isActive()) {
32 5
            return;
33
        }
34
35 2
        $this->items[] = [
36 2
            'service' => $service,
37 2
            'class' => $class,
38 2
            'method' => $method,
39 2
            'arguments' => $arguments,
40 2
            'result' => $result,
41 2
            'status' => $status,
42 2
            'error' => $error,
43 2
            'timeStart' => $timeStart,
44 2
            'timeEnd' => $timeEnd,
45
        ];
46 2
    }
47
48 1
    #[ArrayShape(['totalServices' => 'int|void'])]
49
    public function getIndexData(): array
50
    {
51
        return [
52 1
            'totalServices' => count($this->items),
53
        ];
54
    }
55
56 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...
57
    {
58 1
        $this->items = [];
59 1
    }
60
}
61