1 | <?php |
||
12 | final class SimpleCacheAdapter implements PsrCache |
||
13 | { |
||
14 | /** |
||
15 | * @var DoctrineCache|ClearableCache|MultiGetCache|MultiPutCache |
||
16 | */ |
||
17 | private $doctrineCache; |
||
18 | |||
19 | /** |
||
20 | * @param DoctrineCache $doctrineCache |
||
21 | * @throws \Roave\DoctrineSimpleCache\CacheException |
||
22 | */ |
||
23 | 72 | public function __construct(DoctrineCache $doctrineCache) |
|
37 | |||
38 | /** |
||
39 | * {@inheritDoc} |
||
40 | */ |
||
41 | 29 | public function get($key, $default = null) |
|
50 | |||
51 | /** |
||
52 | * {@inheritDoc} |
||
53 | */ |
||
54 | 37 | public function set($key, $value, $ttl = null) : bool |
|
55 | { |
||
56 | 37 | if ($ttl === null) { |
|
57 | 25 | return $this->doctrineCache->save($key, $value); |
|
58 | } |
||
59 | |||
60 | 13 | if ($ttl instanceof \DateInterval) { |
|
61 | 1 | $ttl = self::convertDateIntervalToInteger($ttl); |
|
62 | } |
||
63 | |||
64 | 13 | if (!is_integer($ttl)) { |
|
65 | 10 | throw InvalidArgumentException::fromKeyAndInvalidTTL($key, $ttl); |
|
66 | } |
||
67 | |||
68 | 3 | if ($ttl <= 0) { |
|
69 | 1 | return $this->delete($key); |
|
70 | } |
||
71 | |||
72 | 2 | return $this->doctrineCache->save($key, $value, $ttl); |
|
73 | } |
||
74 | |||
75 | /** |
||
76 | * {@inheritDoc} |
||
77 | */ |
||
78 | 8 | public function delete($key) : bool |
|
82 | |||
83 | /** |
||
84 | * {@inheritDoc} |
||
85 | */ |
||
86 | 72 | public function clear() : bool |
|
90 | |||
91 | /** |
||
92 | * {@inheritDoc} |
||
93 | */ |
||
94 | 12 | public function getMultiple($keys, $default = null) |
|
98 | |||
99 | /** |
||
100 | * {@inheritDoc} |
||
101 | */ |
||
102 | 24 | public function setMultiple($values, $ttl = null) : bool |
|
103 | { |
||
104 | 24 | if ($ttl === null) { |
|
105 | 12 | return $this->doctrineCache->saveMultiple($values); |
|
106 | } |
||
107 | |||
108 | 12 | if ($ttl instanceof \DateInterval) { |
|
109 | 1 | $ttl = self::convertDateIntervalToInteger($ttl); |
|
110 | } |
||
111 | |||
112 | 12 | if (!is_integer($ttl)) { |
|
113 | 10 | throw InvalidArgumentException::fromKeyAndInvalidTTL(key($values), $ttl); |
|
114 | } |
||
115 | |||
116 | 2 | if ($ttl <= 0) { |
|
117 | 1 | return $this->deleteMultiple(array_keys($values)); |
|
118 | } |
||
119 | |||
120 | 1 | return $this->doctrineCache->saveMultiple($values, $ttl); |
|
121 | } |
||
122 | |||
123 | /** |
||
124 | * {@inheritDoc} |
||
125 | */ |
||
126 | 5 | public function deleteMultiple($keys) : bool |
|
138 | |||
139 | /** |
||
140 | * {@inheritDoc} |
||
141 | */ |
||
142 | 3 | public function has($key) : bool |
|
146 | |||
147 | 2 | private static function convertDateIntervalToInteger(\DateInterval $ttl) : int |
|
148 | { |
||
155 | } |
||
156 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: