Passed
Pull Request — master (#576)
by Dmitriy
12:25 queued 03:07
created

CacheCollector::getCollected()   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 0
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\ModuleFederationProviderInterface;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Yii\Debug\Api\Mo...rationProviderInterface 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
11
class CacheCollector implements ModuleFederationProviderInterface
12
{
13
    use CollectorTrait;
14
15
    public array $set = [];
16
    private array $get = [];
17
18
    public function collectGet(string $key): void
19
    {
20
        $this->get[$key] = [
21
            'key' => $key,
22
            'count' => ($this->get[$key]['count'] ?? 0) + 1,
23
        ];
24
    }
25
26
    public function collectSet(string $key, mixed $value, DateInterval|int|null $ttl): void
27
    {
28
        $this->set[$key] = [
29
            'key' => $key,
30
            'value' => $value,
31
            'ttl' => $ttl,
32
            'count' => ($this->set[$key]['count'] ?? 0) + 1,
33
        ];
34
    }
35
36
    public function getCollected(): array
37
    {
38
        return [
39
            'cache' => [
40
                'get' => array_values($this->get),
41
                'set' => array_values($this->set),
42
            ],
43
        ];
44
    }
45
46
    public function getIndexData(): array
47
    {
48
        return [
49
            'cache' => [
50
                'get' => [
51
                    'total' => array_values($this->get),
52
                ],
53
                'set' => [
54
                    'total' => array_values($this->set),
55
                ],
56
            ],
57
        ];
58
    }
59
60
    public static function getViewPath(): string
61
    {
62
        return '@views/debug/index';
63
    }
64
65
    public static function getAsset(): CacheCollectorAsset
66
    {
67
        return new CacheCollectorAsset();
68
    }
69
}
70