Passed
Push — feature/change-cache-to-profil... ( 160b60 )
by Chema
04:07
created

InMemoryClassNameCache   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 10
c 1
b 0
f 0
dl 0
loc 49
rs 10
ccs 14
cts 14
cp 1

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getAll() 0 3 1
A get() 0 3 1
A has() 0 3 1
A put() 0 3 1
A __construct() 0 3 1
A resetCache() 0 3 1
A getAllFromKey() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gacela\Framework\ClassResolver;
6
7
final class InMemoryClassNameCache implements ClassNameCacheInterface
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 4
    public static function getAllFromKey(string $key): array
23
    {
24 4
        return self::$cache[$key] ?? [];
25
    }
26
27
    /**
28
     * @internal
29
     */
30 11
    public static function resetCache(): void
31
    {
32 11
        self::$cache = [];
33
    }
34
35
    /**
36
     * @return array<string,string>
37
     */
38 2
    public function getAll(): array
39
    {
40 2
        return self::$cache[$this->key] ?? [];
41
    }
42
43 35
    public function has(string $cacheKey): bool
44
    {
45 35
        return isset(self::$cache[$this->key][$cacheKey]);
46
    }
47
48 12
    public function get(string $cacheKey): string
49
    {
50 12
        return self::$cache[$this->key][$cacheKey];
51
    }
52
53 28
    public function put(string $cacheKey, string $className): void
54
    {
55 28
        self::$cache[$this->key][$cacheKey] = $className;
56
    }
57
}
58