InMemoryCache   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Test Coverage

Coverage 75%

Importance

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

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A has() 0 3 1
A all() 0 3 1
A getAllFromKey() 0 3 1
A get() 0 3 1
A resetCache() 0 3 1
A put() 0 3 1
A getAll() 0 3 1
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