Completed
Push — master ( c4d148...c0e5c2 )
by Frederik
02:33
created

NamespaceAdapter::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
namespace Genkgo\Cache\Adapter;
3
4
use Genkgo\Cache\CacheAdapterInterface;
5
6
/**
7
 * Class NamespaceAdapter
8
 * @package Genkgo\Cache
9
 */
10
class NamespaceAdapter implements CacheAdapterInterface
11
{
12
    /**
13
     * @var CacheAdapterInterface
14
     */
15
    private $cache;
16
    /**
17
     * @var string
18
     */
19
    private $nsName;
20
    /**
21
     * @var string
22
     */
23
    private $separator;
24
25
    /**
26
     * @param CacheAdapterInterface $cache
27
     * @param $nsName
28
     * @param string $separator
29
     */
30
    public function __construct(CacheAdapterInterface $cache, $nsName, $separator = '.')
31
    {
32
        $this->cache = $cache;
33
        $this->nsName = $nsName;
34
        $this->separator = $separator;
35
    }
36
37
    /**
38
     * @param $key
39
     * @return mixed|null
40
     */
41
    public function get($key)
42
    {
43
        return $this->cache->get($this->getKey($key));
44
    }
45
46
    /**
47
     * @param $key
48
     * @param $value
49
     */
50
    public function set($key, $value)
51
    {
52
        $this->cache->set($this->getKey($key), $value);
53
    }
54
55
    /**
56
     * @param $key
57
     */
58
    public function delete($key)
59
    {
60
        $this->cache->delete($this->getKey($key));
61
    }
62
63
    /**
64
     * @param $key
65
     * @return string
66
     */
67
    private function getKey($key)
68
    {
69
        return $this->nsName . $this->separator . $key;
70
    }
71
}
72