Completed
Push — develop ( 7dfc1e...e6cbd2 )
by Jens
09:55
created

PsrCacheAdapter::has()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 2
crap 1
1
<?php
2
/**
3
 * @author @jayS-de <[email protected]>
4
 */
5
6
namespace Commercetools\Core\Cache;
7
8
use Psr\Cache\CacheItemPoolInterface;
9
10
class PsrCacheAdapter implements CacheAdapterInterface
11
{
12
    private $pool;
13
14 9
    public function __construct(CacheItemPoolInterface $pool)
15
    {
16 9
        $this->pool = $pool;
17 9
    }
18
19
    /**
20
     * @param $key
21
     * @param null $options
22
     * @return bool|\string[]
23
     */
24 2
    public function has($key, $options = null)
25
    {
26 2
        return $this->pool->hasItem($key);
27
    }
28
29
    /**
30
     * @param $key
31
     * @param mixed $options
32
     * @return mixed|false
33
     */
34 2
    public function fetch($key, $options = null)
35
    {
36 2
        $item = $this->pool->getItem($key);
37 2
        return $item->isHit() ? $item->get() : false;
38
    }
39
40
    /**
41
     * @param $key
42
     * @param $data
43
     * @param $lifeTime
44
     * @param $options
45
     * @return bool
46
     */
47 8
    public function store($key, $data, $lifeTime = null, $options = null)
48
    {
49 8
        $item = $this->pool->getItem($key);
50 8
        $item->set($data);
51 8
        if (!is_null($lifeTime)) {
52 1
            $item->expiresAfter($lifeTime);
53
        }
54 8
        return $this->pool->save($item);
55
    }
56
57
    /**
58
     * @param $key
59
     * @param mixed $options
60
     * @return bool
61
     */
62 2
    public function remove($key, $options = null)
63
    {
64 2
        return $this->pool->deleteItem($key);
65
    }
66
}
67