Test Failed
Pull Request — master (#74)
by Evgeniy
01:53
created

CacheItems::set()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 4
c 1
b 0
f 1
dl 0
loc 8
rs 10
cc 2
nc 2
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Cache\Metadata;
6
7
final class CacheItems
8
{
9
    /**
10
     * @var array<string, CacheItem>
11
     */
12
    private array $items = [];
13
14
    public function expired(string $key, float $beta): bool
15
    {
16
        return isset($this->items[$key]) && $this->items[$key]->expired($beta);
17
    }
18
19
    public function set(string $key, ?int $expiry): void
20
    {
21
        if (isset($this->items[$key])) {
22
            $this->items[$key]->expiry($expiry);
23
            return;
24
        }
25
26
        $this->items[$key] = new CacheItem($expiry);
27
    }
28
29
    public function remove(string $key): void
30
    {
31
        if (isset($this->items[$key])) {
32
            unset($this->items[$key]);
33
        }
34
    }
35
36
    public function clear(): void
37
    {
38
        $this->items = [];
39
    }
40
}
41