1 | <?php |
||
12 | class TestCacheDecorator extends CacheDecorator |
||
13 | { |
||
14 | /** |
||
15 | * Calls made to the cache |
||
16 | * |
||
17 | * @var array |
||
18 | */ |
||
19 | private $calls = [ |
||
20 | 'delete' => [], |
||
21 | 'set' => [], |
||
22 | 'has' => [], |
||
23 | 'get' => [], |
||
24 | 'demand' => [], |
||
25 | 'flush' => false, |
||
26 | ]; |
||
27 | |||
28 | /** |
||
29 | * Checks if an item has been set |
||
30 | * |
||
31 | * @param string $key |
||
32 | * @param mixed $value |
||
33 | * @param int|null $timeToLive |
||
34 | * |
||
35 | * @return bool |
||
36 | */ |
||
37 | public function hasBeenSet($key, $value = null, $timeToLive = null) |
||
47 | |||
48 | /** |
||
49 | * Checks if an item has been checked with the 'has' method |
||
50 | * |
||
51 | * @param string $key |
||
52 | * |
||
53 | * @return bool |
||
54 | */ |
||
55 | public function hasBeenChecked($key) |
||
59 | |||
60 | /** |
||
61 | * Checks if an item has been requested with 'get' |
||
62 | * |
||
63 | * @param string $key |
||
64 | * |
||
65 | * @return bool |
||
66 | */ |
||
67 | public function hasBeenGet($key) |
||
71 | |||
72 | /** |
||
73 | * Checks if an item has been requested with 'demand' |
||
74 | * |
||
75 | * @param string $key |
||
76 | * |
||
77 | * @return bool |
||
78 | */ |
||
79 | public function hasBeenDemanded($key) |
||
83 | |||
84 | /** |
||
85 | * Checks if an item has been deleted |
||
86 | * |
||
87 | * @param string $key |
||
88 | * |
||
89 | * @return bool |
||
90 | */ |
||
91 | public function hasBeenDeleted($key) |
||
95 | |||
96 | /** |
||
97 | * Checks if the cache has been flushed |
||
98 | * |
||
99 | * @return bool |
||
100 | */ |
||
101 | public function hasBeenFlushed() |
||
105 | |||
106 | /** |
||
107 | * @return array |
||
108 | */ |
||
109 | public function getCalls() |
||
113 | |||
114 | /** |
||
115 | * {@inheritdoc} |
||
116 | */ |
||
117 | public function set($key, $value, $timeToLive = 0) |
||
127 | |||
128 | /** |
||
129 | * {@inheritdoc} |
||
130 | */ |
||
131 | public function has($key) |
||
137 | |||
138 | /** |
||
139 | * {@inheritdoc} |
||
140 | */ |
||
141 | public function get($key, $default = null) |
||
147 | |||
148 | /** |
||
149 | * {@inheritdoc} |
||
150 | */ |
||
151 | public function demand($key) |
||
157 | |||
158 | /** |
||
159 | * {@inheritdoc} |
||
160 | */ |
||
161 | public function delete($key) |
||
167 | |||
168 | /** |
||
169 | * {@inheritdoc} |
||
170 | */ |
||
171 | public function flush() |
||
177 | |||
178 | /** |
||
179 | * Tries to match a call by the key |
||
180 | * |
||
181 | * @param array $calls |
||
182 | * @param string $key |
||
183 | * |
||
184 | * @return bool |
||
185 | */ |
||
186 | private function hasBeenDoneByKey(array $calls, $key) |
||
196 | |||
197 | /** |
||
198 | * @param array $set |
||
199 | * @param string $key |
||
200 | * @param mixed $value |
||
201 | * @param null|int $timeToLive |
||
202 | * |
||
203 | * @return bool |
||
204 | */ |
||
205 | private function callMatches(array $set, $key, $value = null, $timeToLive) |
||
217 | |||
218 | /** |
||
219 | * @param mixed $stored |
||
220 | * @param null $expected |
||
221 | * |
||
222 | * @return bool |
||
223 | */ |
||
224 | private function matches($stored, $expected = null) |
||
228 | } |
||
229 |
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.