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 getConfigOption($optionName) |
||
| 162 | { |
||
| 163 | $callback = $this->getGenericCallback(); |
||
| 164 | return $callback(__FUNCTION__, func_get_args()); |
||
| 165 | } |
||
| 166 | |||
| 167 | /** |
||
| 168 | * @return mixed |
||
| 169 | */ |
||
| 170 | public function getDriverName() |
||
| 171 | { |
||
| 172 | $callback = $this->getGenericCallback(); |
||
| 173 | return $callback(__FUNCTION__, func_get_args()); |
||
| 174 | } |
||
| 175 | |||
| 176 | /** |
||
| 177 | * @param string $key |
||
| 178 | * @return mixed |
||
| 179 | */ |
||
| 180 | public function getItem($key) |
||
| 181 | { |
||
| 182 | $callback = $this->getGenericCallback(); |
||
| 183 | return $callback(__FUNCTION__, func_get_args()); |
||
| 184 | } |
||
| 185 | |||
| 186 | /** |
||
| 187 | * @param array $keys |
||
| 188 | * @return mixed |
||
| 189 | */ |
||
| 190 | public function getItems(array $keys = []) |
||
| 191 | { |
||
| 192 | $callback = $this->getGenericCallback(); |
||
| 193 | return $callback(__FUNCTION__, func_get_args()); |
||
| 194 | } |
||
| 195 | |||
| 196 | /** |
||
| 197 | * @param array $keys |
||
| 198 | * @param int $option |
||
| 199 | * @param int $depth |
||
| 200 | * @return mixed |
||
| 201 | */ |
||
| 202 | public function getItemsAsJsonString(array $keys = [], $option = 0, $depth = 512) |
||
| 203 | { |
||
| 204 | $callback = $this->getGenericCallback(); |
||
| 205 | return $callback(__FUNCTION__, func_get_args()); |
||
| 206 | } |
||
| 207 | |||
| 208 | /** |
||
| 209 | * @param \Psr\Cache\CacheItemInterface $item |
||
| 210 | * @return mixed |
||
| 211 | */ |
||
| 212 | public function setItem(CacheItemInterface $item) |
||
| 213 | { |
||
| 214 | $callback = $this->getGenericCallback(); |
||
| 215 | return $callback(__FUNCTION__, func_get_args()); |
||
| 216 | } |
||
| 217 | |||
| 218 | /** |
||
| 219 | * @return mixed |
||
| 220 | */ |
||
| 221 | public function getHelp() |
||
| 226 | |||
| 227 | /** |
||
| 228 | * @return mixed |
||
| 229 | */ |
||
| 230 | public function getStats() |
||
| 235 | |||
| 236 | /** |
||
| 237 | * @param string $tagName |
||
| 238 | * @return mixed |
||
| 239 | */ |
||
| 240 | public function getItemsByTag($tagName) |
||
| 245 | |||
| 246 | /** |
||
| 247 | * @param array $tagNames |
||
| 248 | * @return mixed |
||
| 249 | */ |
||
| 250 | public function getItemsByTags(array $tagNames) |
||
| 255 | |||
| 256 | /** |
||
| 257 | * @param array $tagNames |
||
| 258 | * @param int $option |
||
| 259 | * @param int $depth |
||
| 260 | * @return mixed |
||
| 261 | */ |
||
| 262 | public function getItemsByTagsAsJsonString(array $tagNames, $option = 0, $depth = 512) |
||
| 267 | |||
| 268 | /** |
||
| 269 | * @param string $tagName |
||
| 270 | * @return mixed |
||
| 271 | */ |
||
| 272 | public function deleteItemsByTag($tagName) |
||
| 277 | |||
| 278 | /** |
||
| 279 | * @param array $tagNames |
||
| 280 | * @return mixed |
||
| 281 | */ |
||
| 282 | public function deleteItemsByTags(array $tagNames) |
||
| 287 | |||
| 288 | /** |
||
| 289 | * @param string $tagName |
||
| 290 | * @param int $step |
||
| 291 | * @return mixed |
||
| 292 | */ |
||
| 293 | public function incrementItemsByTag($tagName, $step = 1) |
||
| 298 | |||
| 299 | /** |
||
| 300 | * @param array $tagNames |
||
| 301 | * @param int $step |
||
| 302 | * @return mixed |
||
| 303 | */ |
||
| 304 | public function incrementItemsByTags(array $tagNames, $step = 1) |
||
| 309 | |||
| 310 | /** |
||
| 311 | * @param string $tagName |
||
| 312 | * @param int $step |
||
| 313 | * @return mixed |
||
| 314 | */ |
||
| 315 | public function decrementItemsByTag($tagName, $step = 1) |
||
| 320 | |||
| 321 | /** |
||
| 322 | * @param array $tagNames |
||
| 323 | * @param int $step |
||
| 324 | * @return mixed |
||
| 325 | */ |
||
| 326 | public function decrementItemsByTags(array $tagNames, $step = 1) |
||
| 331 | |||
| 332 | /** |
||
| 333 | * @param string $tagName |
||
| 334 | * @param array|string $data |
||
| 335 | * @return mixed |
||
| 336 | */ |
||
| 337 | public function appendItemsByTag($tagName, $data) |
||
| 342 | |||
| 343 | /** |
||
| 344 | * @param array $tagNames |
||
| 345 | * @param array|string $data |
||
| 346 | * @return mixed |
||
| 347 | */ |
||
| 348 | public function appendItemsByTags(array $tagNames, $data) |
||
| 353 | |||
| 354 | /** |
||
| 355 | * @param string $tagName |
||
| 356 | * @param array|string $data |
||
| 357 | * @return mixed |
||
| 358 | */ |
||
| 359 | public function prependItemsByTag($tagName, $data) |
||
| 364 | |||
| 365 | /** |
||
| 366 | * @param array $tagNames |
||
| 367 | * @param array|string $data |
||
| 368 | * @return mixed |
||
| 369 | */ |
||
| 370 | public function prependItemsByTags(array $tagNames, $data) |
||
| 375 | |||
| 376 | /** |
||
| 377 | * @param array $tagNames |
||
| 378 | * @return mixed |
||
| 379 | */ |
||
| 380 | public function getItemsByTagsAll(array $tagNames) |
||
| 385 | |||
| 386 | /** |
||
| 387 | * @param array $tagNames |
||
| 388 | * @return mixed |
||
| 389 | */ |
||
| 390 | public function deleteItemsByTagsAll(array $tagNames) |
||
| 395 | |||
| 396 | /** |
||
| 397 | * @param array $tagNames |
||
| 398 | * @param int $step |
||
| 399 | * @return mixed |
||
| 400 | */ |
||
| 401 | public function incrementItemsByTagsAll(array $tagNames, $step = 1) |
||
| 406 | |||
| 407 | /** |
||
| 408 | * @param array $tagNames |
||
| 409 | * @param int $step |
||
| 410 | * @return mixed |
||
| 411 | */ |
||
| 412 | public function decrementItemsByTagsAll(array $tagNames, $step = 1) |
||
| 417 | |||
| 418 | /** |
||
| 419 | * @param array $tagNames |
||
| 420 | * @param array|string $data |
||
| 421 | * @return mixed |
||
| 422 | */ |
||
| 423 | public function appendItemsByTagsAll(array $tagNames, $data) |
||
| 428 | |||
| 429 | /** |
||
| 430 | * @param array $tagNames |
||
| 431 | * @param array|string $data |
||
| 432 | * @return mixed |
||
| 433 | */ |
||
| 434 | public function prependItemsByTagsAll(array $tagNames, $data) |
||
| 439 | |||
| 440 | /** |
||
| 441 | * @param \Psr\Cache\CacheItemInterface $item |
||
| 442 | * @return mixed |
||
| 443 | */ |
||
| 444 | public function detachItem(CacheItemInterface $item) |
||
| 449 | |||
| 450 | /** |
||
| 451 | * @return mixed |
||
| 452 | */ |
||
| 453 | public function detachAllItems() |
||
| 458 | |||
| 459 | /** |
||
| 460 | * @param \Psr\Cache\CacheItemInterface $item |
||
| 461 | * @return mixed |
||
| 462 | */ |
||
| 463 | public function attachItem(CacheItemInterface $item) |
||
| 468 | |||
| 469 | /** |
||
| 470 | * @param \Psr\Cache\CacheItemInterface $item |
||
| 471 | * @return mixed |
||
| 472 | */ |
||
| 473 | public function isAttached(CacheItemInterface $item) |
||
| 478 | |||
| 479 | /** |
||
| 480 | * @param \phpFastCache\EventManager $em |
||
| 481 | */ |
||
| 482 | public function setEventManager(EventManager $em) |
||
| 487 | } |