Complex classes like ActOnAll often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ActOnAll, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
25 | class ActOnAll implements ExtendedCacheItemPoolInterface |
||
26 | { |
||
27 | |||
28 | /** |
||
29 | * @var ExtendedCacheItemPoolInterface[] |
||
30 | */ |
||
31 | protected $instances = []; |
||
32 | |||
33 | /** |
||
34 | * ActOnAll constructor. |
||
35 | */ |
||
36 | public function __construct() |
||
40 | |||
41 | /** |
||
42 | * @return \Closure |
||
43 | */ |
||
44 | protected function getGenericCallback() |
||
69 | |||
70 | |||
71 | /** |
||
72 | * @param string $key |
||
73 | * @return mixed |
||
74 | */ |
||
75 | public function hasItem($key) |
||
80 | |||
81 | /** |
||
82 | * @return mixed |
||
83 | */ |
||
84 | public function clear() |
||
89 | |||
90 | /** |
||
91 | * @param string $key |
||
92 | * @return mixed |
||
93 | */ |
||
94 | public function deleteItem($key) |
||
99 | |||
100 | /** |
||
101 | * @param array $keys |
||
102 | * @return mixed |
||
103 | */ |
||
104 | public function deleteItems(array $keys) |
||
109 | |||
110 | /** |
||
111 | * @param \Psr\Cache\CacheItemInterface $item |
||
112 | * @return mixed |
||
113 | */ |
||
114 | public function save(CacheItemInterface $item) |
||
119 | |||
120 | /** |
||
121 | * @param \Psr\Cache\CacheItemInterface $item |
||
122 | * @return mixed |
||
123 | */ |
||
124 | public function saveDeferred(CacheItemInterface $item) |
||
129 | |||
130 | /** |
||
131 | * @param array ...$items |
||
132 | * @return mixed |
||
133 | */ |
||
134 | public function saveMultiple(...$items) |
||
139 | |||
140 | /** |
||
141 | * @return mixed |
||
142 | */ |
||
143 | public function commit() |
||
148 | |||
149 | /** |
||
150 | * @return mixed |
||
151 | */ |
||
152 | public function getConfig() |
||
157 | |||
158 | /** |
||
159 | * @return mixed |
||
160 | */ |
||
161 | public function getDriverName() |
||
166 | |||
167 | /** |
||
168 | * @param string $key |
||
169 | * @return mixed |
||
170 | */ |
||
171 | public function getItem($key) |
||
176 | |||
177 | /** |
||
178 | * @param array $keys |
||
179 | * @return mixed |
||
180 | */ |
||
181 | public function getItems(array $keys = []) |
||
186 | |||
187 | /** |
||
188 | * @param array $keys |
||
189 | * @param int $option |
||
190 | * @param int $depth |
||
191 | * @return mixed |
||
192 | */ |
||
193 | public function getItemsAsJsonString(array $keys = [], $option = 0, $depth = 512) |
||
198 | |||
199 | /** |
||
200 | * @param \Psr\Cache\CacheItemInterface $item |
||
201 | * @return mixed |
||
202 | */ |
||
203 | public function setItem(CacheItemInterface $item) |
||
208 | |||
209 | /** |
||
210 | * @return mixed |
||
211 | */ |
||
212 | public function getHelp() |
||
213 | { |
||
214 | $callback = $this->getGenericCallback(); |
||
215 | return $callback(__FUNCTION__, func_get_args()); |
||
216 | } |
||
217 | |||
218 | /** |
||
219 | * @return mixed |
||
220 | */ |
||
221 | public function getStats() |
||
226 | |||
227 | /** |
||
228 | * @param string $tagName |
||
229 | * @return mixed |
||
230 | */ |
||
231 | public function getItemsByTag($tagName) |
||
236 | |||
237 | /** |
||
238 | * @param array $tagNames |
||
239 | * @return mixed |
||
240 | */ |
||
241 | public function getItemsByTags(array $tagNames) |
||
246 | |||
247 | /** |
||
248 | * @param array $tagNames |
||
249 | * @param int $option |
||
250 | * @param int $depth |
||
251 | * @return mixed |
||
252 | */ |
||
253 | public function getItemsByTagsAsJsonString(array $tagNames, $option = 0, $depth = 512) |
||
258 | |||
259 | /** |
||
260 | * @param string $tagName |
||
261 | * @return mixed |
||
262 | */ |
||
263 | public function deleteItemsByTag($tagName) |
||
268 | |||
269 | /** |
||
270 | * @param array $tagNames |
||
271 | * @return mixed |
||
272 | */ |
||
273 | public function deleteItemsByTags(array $tagNames) |
||
278 | |||
279 | /** |
||
280 | * @param string $tagName |
||
281 | * @param int $step |
||
282 | * @return mixed |
||
283 | */ |
||
284 | public function incrementItemsByTag($tagName, $step = 1) |
||
289 | |||
290 | /** |
||
291 | * @param array $tagNames |
||
292 | * @param int $step |
||
293 | * @return mixed |
||
294 | */ |
||
295 | public function incrementItemsByTags(array $tagNames, $step = 1) |
||
300 | |||
301 | /** |
||
302 | * @param string $tagName |
||
303 | * @param int $step |
||
304 | * @return mixed |
||
305 | */ |
||
306 | public function decrementItemsByTag($tagName, $step = 1) |
||
311 | |||
312 | /** |
||
313 | * @param array $tagNames |
||
314 | * @param int $step |
||
315 | * @return mixed |
||
316 | */ |
||
317 | public function decrementItemsByTags(array $tagNames, $step = 1) |
||
322 | |||
323 | /** |
||
324 | * @param string $tagName |
||
325 | * @param array|string $data |
||
326 | * @return mixed |
||
327 | */ |
||
328 | public function appendItemsByTag($tagName, $data) |
||
333 | |||
334 | /** |
||
335 | * @param array $tagNames |
||
336 | * @param array|string $data |
||
337 | * @return mixed |
||
338 | */ |
||
339 | public function appendItemsByTags(array $tagNames, $data) |
||
344 | |||
345 | /** |
||
346 | * @param string $tagName |
||
347 | * @param array|string $data |
||
348 | * @return mixed |
||
349 | */ |
||
350 | public function prependItemsByTag($tagName, $data) |
||
355 | |||
356 | /** |
||
357 | * @param array $tagNames |
||
358 | * @param array|string $data |
||
359 | * @return mixed |
||
360 | */ |
||
361 | public function prependItemsByTags(array $tagNames, $data) |
||
366 | |||
367 | /** |
||
368 | * @param array $tagNames |
||
369 | * @return mixed |
||
370 | */ |
||
371 | public function getItemsByTagsAll(array $tagNames) |
||
376 | |||
377 | /** |
||
378 | * @param array $tagNames |
||
379 | * @return mixed |
||
380 | */ |
||
381 | public function deleteItemsByTagsAll(array $tagNames) |
||
386 | |||
387 | /** |
||
388 | * @param array $tagNames |
||
389 | * @param int $step |
||
390 | * @return mixed |
||
391 | */ |
||
392 | public function incrementItemsByTagsAll(array $tagNames, $step = 1) |
||
397 | |||
398 | /** |
||
399 | * @param array $tagNames |
||
400 | * @param int $step |
||
401 | * @return mixed |
||
402 | */ |
||
403 | public function decrementItemsByTagsAll(array $tagNames, $step = 1) |
||
408 | |||
409 | /** |
||
410 | * @param array $tagNames |
||
411 | * @param array|string $data |
||
412 | * @return mixed |
||
413 | */ |
||
414 | public function appendItemsByTagsAll(array $tagNames, $data) |
||
419 | |||
420 | /** |
||
421 | * @param array $tagNames |
||
422 | * @param array|string $data |
||
423 | * @return mixed |
||
424 | */ |
||
425 | public function prependItemsByTagsAll(array $tagNames, $data) |
||
430 | |||
431 | /** |
||
432 | * @param \Psr\Cache\CacheItemInterface $item |
||
433 | * @return mixed |
||
434 | */ |
||
435 | public function detachItem(CacheItemInterface $item) |
||
440 | |||
441 | /** |
||
442 | * @return mixed |
||
443 | */ |
||
444 | public function detachAllItems() |
||
449 | |||
450 | /** |
||
451 | * @param \Psr\Cache\CacheItemInterface $item |
||
452 | * @return mixed |
||
453 | */ |
||
454 | public function attachItem(CacheItemInterface $item) |
||
459 | |||
460 | /** |
||
461 | * @param \Psr\Cache\CacheItemInterface $item |
||
462 | * @return mixed |
||
463 | */ |
||
464 | public function isAttached(CacheItemInterface $item) |
||
469 | |||
470 | /** |
||
471 | * @param \phpFastCache\EventManager $em |
||
472 | */ |
||
473 | public function setEventManager(EventManager $em) |
||
478 | } |