Passed
Pull Request — master (#575)
by Dmitriy
03:56 queued 02:24
created

CacheCollector::collectSet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 6
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Debug\CacheCollector;
6
7
use DateInterval;
8
use Yiisoft\Yii\Debug\Api\ViewProviderInterface;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Yii\Debug\Api\ViewProviderInterface 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\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...
10
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...
11
use Yiisoft\Yii\Debug\Collector\IndexCollectorInterface;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Yii\Debug\Collec...IndexCollectorInterface 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...
12
13
class CacheCollector implements CollectorInterface, IndexCollectorInterface, ViewProviderInterface
14
{
15
    use CollectorTrait;
16
17
    public array $set = [];
18
    private array $get = [];
19
20
    public function collectGet(string $key): void
21
    {
22
        $this->get[$key] = $key;
23
    }
24
25
    public function collectSet(string $key, mixed $value, DateInterval|int|null $ttl)
26
    {
27
        $this->set[$key] = [
28
            'key' => $key,
29
            'value' => $value,
30
            'ttl' => $ttl,
31
        ];
32
    }
33
34
    public function getCollected(): array
35
    {
36
        return [
37
            'cache' => [
38
                'get' => array_values($this->get),
39
                'set' => array_values($this->set),
40
            ],
41
        ];
42
    }
43
44
    public function getIndexData(): array
45
    {
46
        return [
47
            'cache' => [
48
                'get' => [
49
                    'total' => array_values($this->get),
50
                ],
51
                'set' => [
52
                    'total' => array_values($this->set),
53
                ],
54
            ],
55
        ];
56
    }
57
58
    public static function getView(): string
59
    {
60
        return '@views/debug/index';
61
    }
62
}
63