NamespaceAdapter::set()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
crap 1
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 3
    public function __construct(CacheAdapterInterface $cache, $nsName, $separator = '.')
31
    {
32 3
        $this->cache = $cache;
33 3
        $this->nsName = $nsName;
34 3
        $this->separator = $separator;
35 3
    }
36
37
    /**
38
     * @param $key
39
     * @return mixed|null
40
     */
41 1
    public function get($key)
42
    {
43 1
        return $this->cache->get($this->getKey($key));
44
    }
45
46
    /**
47
     * @param $key
48
     * @param $value
49
     */
50 1
    public function set($key, $value)
51
    {
52 1
        $this->cache->set($this->getKey($key), $value);
53 1
    }
54
55
    /**
56
     * @param $key
57
     */
58 1
    public function delete($key)
59
    {
60 1
        $this->cache->delete($this->getKey($key));
61 1
    }
62
63
    /**
64
     * @param $key
65
     * @return string
66
     */
67 3
    private function getKey($key)
68
    {
69 3
        return $this->nsName . $this->separator . $key;
70
    }
71
}
72