InMemoryCache::resetCache()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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