Passed
Push — feature/add-config-files ( 1c4158...837ed6 )
by Jesús
05:48 queued 02:26
created

InMemoryCache   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
eloc 9
c 0
b 0
f 0
dl 0
loc 41
ccs 10
cts 12
cp 0.8333
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A put() 0 3 1
A getAll() 0 3 1
A resetCache() 0 3 1
A __construct() 0 3 1
A has() 0 3 1
A get() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gacela\Framework\ClassResolver;
6
7
final class InMemoryCache implements ClassNameCacheInterface
8
{
9
    /** @var array<string,array<string,string>> */
10
    private static array $cache = [];
11
12
    private string $key;
13
14 4
    public function __construct(string $key)
15
    {
16 4
        $this->key = $key;
17
    }
18
19
    /**
20
     * @internal
21
     */
22 2
    public static function getAll(string $key): array
23
    {
24 2
        return self::$cache[$key] ?? [];
25
    }
26
27
    /**
28
     * @internal
29
     */
30
    public static function resetCache(): void
31
    {
32
        self::$cache = [];
33
    }
34
35 4
    public function has(string $cacheKey): bool
36
    {
37 4
        return isset(self::$cache[$this->key][$cacheKey]);
38
    }
39
40 3
    public function get(string $cacheKey): string
41
    {
42 3
        return self::$cache[$this->key][$cacheKey];
43
    }
44
45 2
    public function put(string $cacheKey, string $className): void
46
    {
47 2
        self::$cache[$this->key][$cacheKey] = $className;
48
    }
49
}
50