Passed
Pull Request — master (#70)
by Alexander M.
06:58
created

SimpleCacheAdapter::set()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
dl 0
loc 7
ccs 0
cts 4
cp 0
rs 10
c 1
b 0
f 0
cc 2
nc 2
nop 3
crap 6
1
<?php
0 ignored issues
show
introduced by
Missing declare(strict_types=1).
Loading history...
2
3
namespace Doctrine\Persistence;
4
5
use Doctrine\Common\Cache\Cache;
6
use Psr\SimpleCache\CacheInterface;
7
8
/**
9
 * @internal
10
 */
11
final class SimpleCacheAdapter implements CacheInterface
12
{
13
    /** @var Cache */
14
    private $wrapped;
15
16
    public function __construct(Cache $wrapped)
17
    {
18
        $this->wrapped = $wrapped;
19
    }
20
21
    public function unwrap(): Cache
0 ignored issues
show
introduced by
There must be exactly 1 whitespace between closing parenthesis and return type colon.
Loading history...
22
    {
23
        return $this->wrapped;
24
    }
25
26
    /**
27
     * @inheritDoc
28
     */
29
    public function get($key, $default = null)
30
    {
31
        $cachedValue = $this->wrapped->fetch($key);
32
33
        return false === $cachedValue ? $default : $cachedValue;
0 ignored issues
show
introduced by
Yoda comparisons are disallowed.
Loading history...
34
    }
35
36
    /**
37
     * @inheritDoc
38
     */
39
    public function set($key, $value, $ttl = null): bool
0 ignored issues
show
introduced by
There must be exactly 1 whitespace between closing parenthesis and return type colon.
Loading history...
40
    {
41
        if (null !== $ttl) {
0 ignored issues
show
introduced by
Yoda comparisons are disallowed.
Loading history...
42
            throw new \InvalidArgumentException('Setting a TTL is not supported.');
0 ignored issues
show
introduced by
Class \InvalidArgumentException should not be referenced via a fully qualified name, but via a use statement.
Loading history...
43
        }
44
45
        return $this->wrapped->save($key, $value);
46
    }
47
48
    /**
49
     * @inheritDoc
50
     */
51
    public function delete($key): bool
0 ignored issues
show
introduced by
There must be exactly 1 whitespace between closing parenthesis and return type colon.
Loading history...
52
    {
53
        throw new \BadMethodCallException(sprintf('%s is not implemented.', __METHOD__));
0 ignored issues
show
introduced by
Class \BadMethodCallException should not be referenced via a fully qualified name, but via a use statement.
Loading history...
introduced by
Function sprintf() should not be referenced via a fallback global name, but via a use statement.
Loading history...
54
    }
55
56
    /**
57
     * @inheritDoc
58
     */
59
    public function clear(): bool
0 ignored issues
show
introduced by
There must be exactly 1 whitespace between closing parenthesis and return type colon.
Loading history...
60
    {
61
        throw new \BadMethodCallException(sprintf('%s is not implemented.', __METHOD__));
0 ignored issues
show
introduced by
Class \BadMethodCallException should not be referenced via a fully qualified name, but via a use statement.
Loading history...
introduced by
Function sprintf() should not be referenced via a fallback global name, but via a use statement.
Loading history...
62
    }
63
64
    /**
65
     * @inheritDoc
66
     */
67
    public function getMultiple($keys, $default = null): iterable
0 ignored issues
show
introduced by
There must be exactly 1 whitespace between closing parenthesis and return type colon.
Loading history...
68
    {
69
        throw new \BadMethodCallException(sprintf('%s is not implemented.', __METHOD__));
0 ignored issues
show
introduced by
Class \BadMethodCallException should not be referenced via a fully qualified name, but via a use statement.
Loading history...
introduced by
Function sprintf() should not be referenced via a fallback global name, but via a use statement.
Loading history...
70
    }
71
72
    /**
73
     * @inheritDoc
74
     */
75
    public function setMultiple($values, $ttl = null): bool
0 ignored issues
show
introduced by
There must be exactly 1 whitespace between closing parenthesis and return type colon.
Loading history...
76
    {
77
        throw new \BadMethodCallException(sprintf('%s is not implemented.', __METHOD__));
0 ignored issues
show
introduced by
Class \BadMethodCallException should not be referenced via a fully qualified name, but via a use statement.
Loading history...
introduced by
Function sprintf() should not be referenced via a fallback global name, but via a use statement.
Loading history...
78
    }
79
80
    /**
81
     * @inheritDoc
82
     */
83
    public function deleteMultiple($keys): bool
0 ignored issues
show
introduced by
There must be exactly 1 whitespace between closing parenthesis and return type colon.
Loading history...
84
    {
85
        throw new \BadMethodCallException(sprintf('%s is not implemented.', __METHOD__));
0 ignored issues
show
introduced by
Class \BadMethodCallException should not be referenced via a fully qualified name, but via a use statement.
Loading history...
introduced by
Function sprintf() should not be referenced via a fallback global name, but via a use statement.
Loading history...
86
    }
87
88
    /**
89
     * @inheritDoc
90
     */
91
    public function has($key): bool
0 ignored issues
show
introduced by
There must be exactly 1 whitespace between closing parenthesis and return type colon.
Loading history...
92
    {
93
        return $this->wrapped->contains($key);
94
    }
95
}
96