Completed
Push — master ( 277825...31cee4 )
by Dominik
01:47
created

EntryCache::remove()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\Model\Cache;
6
7
final class EntryCache implements EntryCacheInterface
8
{
9
    /**
10
     * @var array
11
     */
12
    private $cache = [];
13
14
    /**
15
     * @param string $id
16
     * @param array  $entry
17
     *
18
     * @return EntryCacheInterface
19
     */
20
    public function set(string $id, array $entry): EntryCacheInterface
21
    {
22
        $this->cache[$id] = $entry;
23
24
        return $this;
25
    }
26
27
    /**
28
     * @param string $id
29
     *
30
     * @return bool
31
     */
32
    public function has(string $id): bool
33
    {
34
        return array_key_exists($id, $this->cache);
35
    }
36
37
    /**
38
     * @param string $id
39
     *
40
     * @return array
41
     *
42
     * @throws EntryNotFoundException
43
     */
44
    public function get(string $id)
45
    {
46
        if (!$this->has($id)) {
47
            throw EntryNotFoundException::fromId($id);
48
        }
49
50
        return $this->cache[$id];
51
    }
52
53
    /**
54
     * @param string $id
55
     *
56
     * @return EntryCacheInterface
57
     */
58
    public function remove(string $id): EntryCacheInterface
59
    {
60
        unset($this->cache[$id]);
61
62
        return $this;
63
    }
64
65
    /**
66
     * @return EntryCacheInterface
67
     */
68
    public function clear(): EntryCacheInterface
69
    {
70
        $this->cache = [];
71
72
        return $this;
73
    }
74
}
75