Passed
Pull Request — master (#575)
by Dmitriy
09:11
created

CacheCollector   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
c 1
b 0
f 0
dl 0
loc 48
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A collectSet() 0 6 1
A getView() 0 3 1
A getCollected() 0 6 1
A collectGet() 0 3 1
A getSummary() 0 9 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Debug\CacheCollector;
6
7
use DateInterval;
8
use Yiisoft\Yii\Debug\Collector\CollectorInterface;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Yii\Debug\Collector\CollectorInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Yiisoft\Yii\Debug\Collector\CollectorTrait;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Yii\Debug\Collector\CollectorTrait was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Yiisoft\Yii\Debug\Collector\SummaryCollectorInterface;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Yii\Debug\Collec...mmaryCollectorInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
12
class CacheCollector implements CollectorInterface, SummaryCollectorInterface
13
{
14
    use CollectorTrait;
15
16
    public array $set = [];
17
    private array $get = [];
18
19
    public function collectGet(string $key): void
20
    {
21
        $this->get[$key] = $key;
22
    }
23
24
    public function collectSet(string $key, mixed $value, DateInterval|int|null $ttl)
25
    {
26
        $this->set[$key] = [
27
            'key' => $key,
28
            'value' => $value,
29
            'ttl' => $ttl,
30
        ];
31
    }
32
33
    public function getCollected(): array
34
    {
35
        return [
36
            'cache' => [
37
                'get' => array_values($this->get),
38
                'set' => array_values($this->set),
39
            ],
40
        ];
41
    }
42
43
    public function getSummary(): array
44
    {
45
        return [
46
            'cache' => [
47
                'get' => [
48
                    'total' => array_values($this->get),
49
                ],
50
                'set' => [
51
                    'total' => array_values($this->set),
52
                ],
53
            ],
54
        ];
55
    }
56
57
    public static function getView(): string
58
    {
59
        return '@views/debug/index';
60
    }
61
}
62