Failed Conditions
Pull Request — master (#70)
by Alexander M.
02:45
created

SimpleCacheAdapter   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 12
eloc 14
c 1
b 0
f 0
dl 0
loc 83
ccs 0
cts 24
cp 0
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A has() 0 3 1
A set() 0 7 2
A clear() 0 3 1
A get() 0 5 2
A delete() 0 3 1
A __construct() 0 3 1
A deleteMultiple() 0 3 1
A setMultiple() 0 3 1
A unwrap() 0 3 1
A getMultiple() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Persistence;
6
7
use BadMethodCallException;
8
use Doctrine\Common\Cache\Cache;
9
use InvalidArgumentException;
10
use Psr\SimpleCache\CacheInterface;
11
use function sprintf;
12
13
/**
14
 * @internal
15
 */
16
final class SimpleCacheAdapter implements CacheInterface
17
{
18
    /** @var Cache */
19
    private $wrapped;
20
21
    public function __construct(Cache $wrapped)
22
    {
23
        $this->wrapped = $wrapped;
24
    }
25
26
    public function unwrap() : Cache
27
    {
28
        return $this->wrapped;
29
    }
30
31
    /**
32
     * @inheritDoc
33
     */
34
    public function get($key, $default = null)
35
    {
36
        $cachedValue = $this->wrapped->fetch($key);
37
38
        return $cachedValue === false ? $default : $cachedValue;
39
    }
40
41
    /**
42
     * @inheritDoc
43
     */
44
    public function set($key, $value, $ttl = null) : bool
45
    {
46
        if ($ttl !== null) {
47
            throw new InvalidArgumentException('Setting a TTL is not supported.');
48
        }
49
50
        return $this->wrapped->save($key, $value);
51
    }
52
53
    /**
54
     * @inheritDoc
55
     */
56
    public function delete($key) : bool
57
    {
58
        throw new BadMethodCallException(sprintf('%s is not implemented.', __METHOD__));
59
    }
60
61
    /**
62
     * @inheritDoc
63
     */
64
    public function clear() : bool
65
    {
66
        throw new BadMethodCallException(sprintf('%s is not implemented.', __METHOD__));
67
    }
68
69
    /**
70
     * @inheritDoc
71
     */
72
    public function getMultiple($keys, $default = null) : iterable
73
    {
74
        throw new BadMethodCallException(sprintf('%s is not implemented.', __METHOD__));
75
    }
76
77
    /**
78
     * @inheritDoc
79
     */
80
    public function setMultiple($values, $ttl = null) : bool
81
    {
82
        throw new BadMethodCallException(sprintf('%s is not implemented.', __METHOD__));
83
    }
84
85
    /**
86
     * @inheritDoc
87
     */
88
    public function deleteMultiple($keys) : bool
89
    {
90
        throw new BadMethodCallException(sprintf('%s is not implemented.', __METHOD__));
91
    }
92
93
    /**
94
     * @inheritDoc
95
     */
96
    public function has($key) : bool
97
    {
98
        return $this->wrapped->contains($key);
99
    }
100
}
101