| Total Complexity | 8 |
| Total Lines | 45 |
| 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 | * |
||
| 26 | * @return mixed|null |
||
| 27 | */ |
||
| 28 | 5 | public function getValue(string $key, float $beta, CacheInterface $cache) |
|
| 29 | { |
||
| 30 | 5 | if (isset($this->items[$key]) && !$this->items[$key]->expired($beta, $cache)) { |
|
| 31 | 5 | return $this->items[$key]->value(); |
|
| 32 | } |
||
| 33 | |||
| 34 | 2 | return null; |
|
| 35 | } |
||
| 36 | |||
| 37 | 41 | public function set(CacheItem $item): void |
|
| 38 | { |
||
| 39 | 41 | $key = $item->key(); |
|
| 40 | |||
| 41 | 41 | if (!isset($this->items[$key])) { |
|
| 42 | 41 | $this->items[$key] = $item; |
|
| 43 | 41 | return; |
|
| 44 | } |
||
| 45 | |||
| 46 | 2 | $this->items[$key]->update($item->value(), $item->expiry(), $item->dependency()); |
|
| 47 | 2 | } |
|
| 48 | |||
| 49 | 13 | public function remove(string $key): void |
|
| 50 | { |
||
| 51 | 13 | if (isset($this->items[$key])) { |
|
| 52 | 13 | unset($this->items[$key]); |
|
| 53 | } |
||
| 54 | 13 | } |
|
| 55 | |||
| 56 | 48 | public function has(string $key): bool |
|
| 59 | } |
||
| 60 | } |
||
| 61 |