Test Failed
Push — master ( 73c405...d57cd2 )
by Konstantins
03:14
created

Cache::has()   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 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php declare(strict_types = 1);
2
3
namespace Venta\Cache;
4
5
use Cache\Adapter\Common\CacheItem;
6
use Psr\Cache\CacheItemPoolInterface;
7
use Venta\Contracts\Cache\Cache as CacheContract;
8
9
/**
10
 * Class Cache
11
 *
12
 * @package Venta\Cache
13
 */
14
final class Cache implements CacheContract
15
{
16
17
    /**
18
     * @var CacheItemPoolInterface
19
     */
20
    private $pool;
21
22
    /**
23
     * Repository constructor.
24
     *
25
     * @param CacheItemPoolInterface $pool
26
     */
27 1
    public function __construct(CacheItemPoolInterface $pool)
28
    {
29 1
        $this->pool = $pool;
30 1
    }
31
32
    /**
33
     * @inheritDoc
34
     */
35
    public function delete(string $key): bool
36
    {
37
        return $this->pool->deleteItem($key);
38
    }
39
40
    /**
41
     * @inheritDoc
42
     */
43
    public function get(string $key)
44
    {
45
        return $this->pool->getItem($key)->get();
46
    }
47
48
    /**
49
     * @inheritDoc
50
     */
51
    public function has(string $key): bool
52
    {
53
        return $this->pool->hasItem($key);
54
    }
55
56
    /**
57
     * @inheritDoc
58
     */
59
    public function put(string $key, $value, $expires): bool
60
    {
61
        $item = new CacheItem($key);
62
        $item->set($value);
63
        if (is_int($expires) || $expires instanceof \DateInterval) {
64
            $item->expiresAfter($expires);
65
        } elseif ($expires instanceof \DateTimeInterface) { // @codeCoverageIgnore
66
            $item->expiresAt($expires);
67
        }
68
69
        return $this->pool->save($item);
70
    }
71
72
    /**
73
     * @inheritDoc
74
     */
75
    public function set(string $key, $value): bool
76
    {
77
        return $this->pool->save((new CacheItem($key))->set($value));
78
    }
79
80
}
81