InMemoryCache::get()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace Tkotosz\CatalogRouter\Model\Service\Cache;
4
5
use Tkotosz\CatalogRouter\Api\CacheInterface;
6
7
class InMemoryCache implements CacheInterface
8
{
9
    /**
10
     * @var array
11
     */
12
    private $cache;
13
14
    /**
15
     * @param string $key
16
     * @param mixed  $value
17
     */
18
    public function set(string $key, $value)
19
    {
20
        $this->cache[$key] = $value;
21
    }
22
23
    /**
24
     * @param string $key
25
     *
26
     * @return boolean
27
     */
28
    public function has(string $key) : bool
29
    {
30
        return isset($this->cache[$key]);
31
    }
32
33
    /**
34
     * @param string $key
35
     *
36
     * @return mixed
37
     */
38
    public function get(string $key)
39
    {
40
        if (!isset($this->cache[$key])) {
41
            throw new \Exception(sprintf('%s cache does not contain %s key', $storage, $key));
42
        }
43
        
44
        return $this->cache[$key];
45
    }
46
}
47