InMemoryCache::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 1
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
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