Total Complexity | 8 |
Total Lines | 44 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 3 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
14 | final class CacheItems |
||
15 | { |
||
16 | /** |
||
17 | * @var array<string, CacheItem> |
||
18 | */ |
||
19 | private array $items = []; |
||
20 | |||
21 | /** |
||
22 | * @param string $key |
||
23 | * @param float $beta |
||
24 | * @param CacheInterface $cache |
||
25 | * @return mixed|null |
||
26 | */ |
||
27 | 5 | public function getValue(string $key, float $beta, CacheInterface $cache) |
|
28 | { |
||
29 | 5 | if (isset($this->items[$key]) && !$this->items[$key]->expired($beta, $cache)) { |
|
30 | 5 | return $this->items[$key]->value(); |
|
31 | } |
||
32 | |||
33 | 2 | return null; |
|
34 | } |
||
35 | |||
36 | 41 | public function set(CacheItem $item): void |
|
37 | { |
||
38 | 41 | $key = $item->key(); |
|
39 | |||
40 | 41 | if (!isset($this->items[$key])) { |
|
41 | 41 | $this->items[$key] = $item; |
|
42 | 41 | return; |
|
43 | } |
||
44 | |||
45 | 2 | $this->items[$key]->update($item->value(), $item->expiry(), $item->dependency()); |
|
46 | 2 | } |
|
47 | |||
48 | 13 | public function remove(string $key): void |
|
49 | { |
||
50 | 13 | if (isset($this->items[$key])) { |
|
51 | 13 | unset($this->items[$key]); |
|
52 | } |
||
53 | 13 | } |
|
54 | |||
55 | 48 | public function has(string $key): bool |
|
58 | } |
||
59 | } |
||
60 |