InMemoryCache   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
wmc 8
eloc 13
c 0
b 0
f 0
dl 0
loc 63
ccs 12
cts 16
cp 0.75
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A has() 0 4 1
A __construct() 0 3 1
A all() 0 3 1
A getAllFromKey() 0 3 1
A get() 0 4 1
A resetCache() 0 3 1
A put() 0 4 1
A getAll() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gacela\Framework\ClassResolver\Cache;
6
7
use Override;
8
9
final class InMemoryCache implements CacheInterface
10
{
11
    /** @var array<string, array<string,string>> */
12 53
    private static array $cache = [];
13
14
    public function __construct(
15 53
        private readonly string $key,
16
    ) {
17
    }
18
19
    /**
20 2
     * @internal
21
     *
22 2
     * @return array<string, string>
23
     */
24
    public static function getAllFromKey(string $key): array
25
    {
26
        return self::$cache[$key] ?? [];
27
    }
28
29
    /**
30
     * @internal
31
     *
32
     * @return array<string, array<string,string>>
33
     */
34
    public static function all(): array
35
    {
36 58
        return self::$cache;
37
    }
38 58
39
    /**
40
     * @internal
41
     */
42
    public static function resetCache(): void
43
    {
44
        self::$cache = [];
45
    }
46
47
    /**
48
     * @return array<string, string>
49 74
     */
50
    #[Override]
51 74
    public function getAll(): array
52
    {
53
        return self::$cache[$this->key] ?? [];
54 29
    }
55
56 29
    #[Override]
57
    public function has(string $cacheKey): bool
58
    {
59 58
        return isset(self::$cache[$this->key][$cacheKey]);
60
    }
61 58
62
    #[Override]
63
    public function get(string $cacheKey): string
64
    {
65
        return self::$cache[$this->key][$cacheKey];
66
    }
67
68
    #[Override]
69
    public function put(string $cacheKey, string $className): void
70
    {
71
        self::$cache[$this->key][$cacheKey] = $className;
72
    }
73
}
74