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 |
||
| 15 | class ActOnAll implements ExtendedCacheItemPoolInterface |
||
| 16 | { |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @var array|\phpFastCache\Core\Pool\ExtendedCacheItemPoolInterface[] |
||
| 20 | */ |
||
| 21 | protected $instances = []; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * ActOnAll constructor. |
||
| 25 | */ |
||
| 26 | public function __construct() |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @return \Closure |
||
| 33 | */ |
||
| 34 | protected function getGenericCallback() |
||
| 59 | |||
| 60 | |||
| 61 | /** |
||
| 62 | * @param string $key |
||
| 63 | * @return mixed |
||
| 64 | */ |
||
| 65 | public function hasItem($key) |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @return mixed |
||
| 73 | */ |
||
| 74 | public function clear() |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @param string $key |
||
| 82 | * @return mixed |
||
| 83 | */ |
||
| 84 | public function deleteItem($key) |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @param array $keys |
||
| 92 | * @return mixed |
||
| 93 | */ |
||
| 94 | public function deleteItems(array $keys) |
||
| 99 | |||
| 100 | /** |
||
| 101 | * @param \Psr\Cache\CacheItemInterface $item |
||
| 102 | * @return mixed |
||
| 103 | */ |
||
| 104 | public function save(CacheItemInterface $item) |
||
| 109 | |||
| 110 | /** |
||
| 111 | * @param \Psr\Cache\CacheItemInterface $item |
||
| 112 | * @return mixed |
||
| 113 | */ |
||
| 114 | public function saveDeferred(CacheItemInterface $item) |
||
| 119 | |||
| 120 | /** |
||
| 121 | * @param array ...$items |
||
| 122 | * @return mixed |
||
| 123 | */ |
||
| 124 | public function saveMultiple(...$items) |
||
| 129 | |||
| 130 | /** |
||
| 131 | * @return mixed |
||
| 132 | */ |
||
| 133 | public function commit() |
||
| 138 | |||
| 139 | /** |
||
| 140 | * @return mixed |
||
| 141 | */ |
||
| 142 | public function getConfig() |
||
| 147 | |||
| 148 | /** |
||
| 149 | * @return mixed |
||
| 150 | */ |
||
| 151 | public function getDriverName() |
||
| 156 | |||
| 157 | /** |
||
| 158 | * @param string $key |
||
| 159 | * @return mixed |
||
| 160 | */ |
||
| 161 | public function getItem($key) |
||
| 166 | |||
| 167 | /** |
||
| 168 | * @param array $keys |
||
| 169 | * @return mixed |
||
| 170 | */ |
||
| 171 | public function getItems(array $keys = []) |
||
| 176 | |||
| 177 | /** |
||
| 178 | * @param array $keys |
||
| 179 | * @param int $option |
||
| 180 | * @param int $depth |
||
| 181 | * @return mixed |
||
| 182 | */ |
||
| 183 | public function getItemsAsJsonString(array $keys = [], $option = 0, $depth = 512) |
||
| 188 | |||
| 189 | /** |
||
| 190 | * @param \Psr\Cache\CacheItemInterface $item |
||
| 191 | * @return mixed |
||
| 192 | */ |
||
| 193 | public function setItem(CacheItemInterface $item) |
||
| 198 | |||
| 199 | /** |
||
| 200 | * @return mixed |
||
| 201 | */ |
||
| 202 | public function clean() |
||
| 207 | |||
| 208 | /** |
||
| 209 | * @return mixed |
||
| 210 | */ |
||
| 211 | public function getStats() |
||
| 216 | |||
| 217 | /** |
||
| 218 | * @param string $tagName |
||
| 219 | * @return mixed |
||
| 220 | */ |
||
| 221 | public function getItemsByTag($tagName) |
||
| 226 | |||
| 227 | /** |
||
| 228 | * @param array $tagNames |
||
| 229 | * @return mixed |
||
| 230 | */ |
||
| 231 | public function getItemsByTags(array $tagNames) |
||
| 236 | |||
| 237 | /** |
||
| 238 | * @param array $tagNames |
||
| 239 | * @param int $option |
||
| 240 | * @param int $depth |
||
| 241 | * @return mixed |
||
| 242 | */ |
||
| 243 | public function getItemsByTagsAsJsonString(array $tagNames, $option = 0, $depth = 512) |
||
| 248 | |||
| 249 | /** |
||
| 250 | * @param string $tagName |
||
| 251 | * @return mixed |
||
| 252 | */ |
||
| 253 | public function deleteItemsByTag($tagName) |
||
| 258 | |||
| 259 | /** |
||
| 260 | * @param array $tagNames |
||
| 261 | * @return mixed |
||
| 262 | */ |
||
| 263 | public function deleteItemsByTags(array $tagNames) |
||
| 268 | |||
| 269 | /** |
||
| 270 | * @param string $tagName |
||
| 271 | * @param int $step |
||
| 272 | * @return mixed |
||
| 273 | */ |
||
| 274 | public function incrementItemsByTag($tagName, $step = 1) |
||
| 279 | |||
| 280 | /** |
||
| 281 | * @param array $tagNames |
||
| 282 | * @param int $step |
||
| 283 | * @return mixed |
||
| 284 | */ |
||
| 285 | public function incrementItemsByTags(array $tagNames, $step = 1) |
||
| 290 | |||
| 291 | /** |
||
| 292 | * @param string $tagName |
||
| 293 | * @param int $step |
||
| 294 | * @return mixed |
||
| 295 | */ |
||
| 296 | public function decrementItemsByTag($tagName, $step = 1) |
||
| 301 | |||
| 302 | /** |
||
| 303 | * @param array $tagNames |
||
| 304 | * @param int $step |
||
| 305 | * @return mixed |
||
| 306 | */ |
||
| 307 | public function decrementItemsByTags(array $tagNames, $step = 1) |
||
| 312 | |||
| 313 | /** |
||
| 314 | * @param string $tagName |
||
| 315 | * @param array|string $data |
||
| 316 | * @return mixed |
||
| 317 | */ |
||
| 318 | public function appendItemsByTag($tagName, $data) |
||
| 323 | |||
| 324 | /** |
||
| 325 | * @param array $tagNames |
||
| 326 | * @param array|string $data |
||
| 327 | * @return mixed |
||
| 328 | */ |
||
| 329 | public function appendItemsByTags(array $tagNames, $data) |
||
| 334 | |||
| 335 | /** |
||
| 336 | * @param string $tagName |
||
| 337 | * @param array|string $data |
||
| 338 | * @return mixed |
||
| 339 | */ |
||
| 340 | public function prependItemsByTag($tagName, $data) |
||
| 345 | |||
| 346 | /** |
||
| 347 | * @param array $tagNames |
||
| 348 | * @param array|string $data |
||
| 349 | * @return mixed |
||
| 350 | */ |
||
| 351 | public function prependItemsByTags(array $tagNames, $data) |
||
| 356 | |||
| 357 | /** |
||
| 358 | * @param array $tagNames |
||
| 359 | * @return mixed |
||
| 360 | */ |
||
| 361 | public function getItemsByTagsAll(array $tagNames) |
||
| 366 | |||
| 367 | /** |
||
| 368 | * @param array $tagNames |
||
| 369 | * @return mixed |
||
| 370 | */ |
||
| 371 | public function deleteItemsByTagsAll(array $tagNames) |
||
| 376 | |||
| 377 | /** |
||
| 378 | * @param array $tagNames |
||
| 379 | * @param int $step |
||
| 380 | * @return mixed |
||
| 381 | */ |
||
| 382 | public function incrementItemsByTagsAll(array $tagNames, $step = 1) |
||
| 387 | |||
| 388 | /** |
||
| 389 | * @param array $tagNames |
||
| 390 | * @param int $step |
||
| 391 | * @return mixed |
||
| 392 | */ |
||
| 393 | public function decrementItemsByTagsAll(array $tagNames, $step = 1) |
||
| 398 | |||
| 399 | /** |
||
| 400 | * @param array $tagNames |
||
| 401 | * @param array|string $data |
||
| 402 | * @return mixed |
||
| 403 | */ |
||
| 404 | public function appendItemsByTagsAll(array $tagNames, $data) |
||
| 409 | |||
| 410 | /** |
||
| 411 | * @param array $tagNames |
||
| 412 | * @param array|string $data |
||
| 413 | * @return mixed |
||
| 414 | */ |
||
| 415 | public function prependItemsByTagsAll(array $tagNames, $data) |
||
| 420 | |||
| 421 | /** |
||
| 422 | * @param \Psr\Cache\CacheItemInterface $item |
||
| 423 | * @return mixed |
||
| 424 | */ |
||
| 425 | public function detachItem(CacheItemInterface $item) |
||
| 430 | |||
| 431 | /** |
||
| 432 | * @return mixed |
||
| 433 | */ |
||
| 434 | public function detachAllItems() |
||
| 439 | |||
| 440 | /** |
||
| 441 | * @param \Psr\Cache\CacheItemInterface $item |
||
| 442 | * @return mixed |
||
| 443 | */ |
||
| 444 | public function attachItem(CacheItemInterface $item) |
||
| 449 | |||
| 450 | /** |
||
| 451 | * @param \Psr\Cache\CacheItemInterface $item |
||
| 452 | * @return mixed |
||
| 453 | */ |
||
| 454 | public function isAttached(CacheItemInterface $item) |
||
| 459 | |||
| 460 | /** |
||
| 461 | * @param \phpFastCache\EventManager $em |
||
| 462 | */ |
||
| 463 | public function setEventManager(EventManager $em) |
||
| 468 | } |