Passed
Push — master ( 51a94b...0f3d7a )
by Jesús
01:31 queued 13s
created

InMemoryCache   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
wmc 8
eloc 11
c 0
b 0
f 0
dl 0
loc 57
rs 10
ccs 14
cts 16
cp 0.875

8 Methods

Rating   Name   Duplication   Size   Complexity  
A has() 0 3 1
A __construct() 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
    private string $key;
13
14 35
    public function __construct(string $key)
15
    {
16 35
        $this->key = $key;
17
    }
18
19
    /**
20
     * @internal
21
     */
22 2
    public static function getAllFromKey(string $key): array
23
    {
24 2
        return self::$cache[$key] ?? [];
25
    }
26
27
    /**
28
     * @internal
29
     */
30
    public static function all(): array
31
    {
32
        return self::$cache;
33
    }
34
35
    /**
36
     * @internal
37
     */
38 10
    public static function resetCache(): void
39
    {
40 10
        self::$cache = [];
41
    }
42
43
    /**
44
     * @return array<string, string>
45
     */
46 1
    public function getAll(): array
47
    {
48 1
        return self::$cache[$this->key] ?? [];
49
    }
50
51 35
    public function has(string $cacheKey): bool
52
    {
53 35
        return isset(self::$cache[$this->key][$cacheKey]);
54
    }
55
56 18
    public function get(string $cacheKey): string
57
    {
58 18
        return self::$cache[$this->key][$cacheKey];
59
    }
60
61 23
    public function put(string $cacheKey, string $className): void
62
    {
63 23
        self::$cache[$this->key][$cacheKey] = $className;
64
    }
65
}
66