InMemoryCache   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 40
c 0
b 0
f 0
wmc 4
lcom 1
cbo 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A set() 0 4 1
A has() 0 4 1
A get() 0 8 2
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