Complex classes like classCache 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 classCache, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 27 | class classCache implements ArrayAccess { |
||
| 28 | const CACHER_NOT_INIT = -1; |
||
| 29 | const CACHER_NO_CACHE = 0; |
||
| 30 | const CACHER_XCACHE = 1; |
||
| 31 | |||
| 32 | // CACHER_NOT_INIT - not initialized |
||
| 33 | // CACHER_NO_CACHE - no cache - array() used |
||
| 34 | // CACHER_XCACHE - xCache |
||
| 35 | protected static $mode = self::CACHER_NOT_INIT; |
||
| 36 | protected static $data; |
||
| 37 | protected $prefix; |
||
| 38 | |||
| 39 | protected static $cacheObject; |
||
| 40 | |||
| 41 | public function __construct($prefIn = 'CACHE_', $init_mode = false) { |
||
| 60 | |||
| 61 | public static function getInstance($prefIn = 'CACHE_', $table_name = '') { |
||
| 69 | |||
| 70 | public final function __clone() { |
||
| 74 | |||
| 75 | /** |
||
| 76 | * @return int |
||
| 77 | */ |
||
| 78 | public function getMode() { |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @return string |
||
| 84 | */ |
||
| 85 | public function getPrefix() { |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @param $prefix |
||
| 91 | */ |
||
| 92 | public function setPrefix($prefix) { |
||
| 95 | |||
| 96 | // ------------------------------------------------------------------------- |
||
| 97 | // Here comes low-level functions - those that directly works with cacher engines |
||
| 98 | // ------------------------------------------------------------------------- |
||
| 99 | public function __set($name, $value) { |
||
| 110 | |||
| 111 | public function __get($name) { |
||
| 124 | |||
| 125 | public function __isset($name) { |
||
| 138 | |||
| 139 | public function __unset($name) { |
||
| 150 | |||
| 151 | public function unset_by_prefix($prefix_unset = '') { |
||
| 176 | // ------------------------------------------------------------------------- |
||
| 177 | // End of low-level functions |
||
| 178 | // ------------------------------------------------------------------------- |
||
| 179 | |||
| 180 | protected function make_element_name($args, $diff = 0) { |
||
| 196 | |||
| 197 | public function array_set() { |
||
| 219 | |||
| 220 | public function array_get() { |
||
| 228 | |||
| 229 | public function array_count() { |
||
| 242 | |||
| 243 | public function array_unset() { |
||
| 265 | |||
| 266 | public function dumpData() { |
||
| 277 | |||
| 278 | public function reset() { |
||
| 283 | |||
| 284 | public function init($reInit = false) { |
||
| 287 | |||
| 288 | public function isInitialized() { |
||
| 291 | |||
| 292 | /** |
||
| 293 | * Whether a offset exists |
||
| 294 | * @link http://php.net/manual/en/arrayaccess.offsetexists.php |
||
| 295 | * |
||
| 296 | * @param mixed $offset <p> |
||
| 297 | * An offset to check for. |
||
| 298 | * </p> |
||
| 299 | * |
||
| 300 | * @return boolean true on success or false on failure. |
||
| 301 | * </p> |
||
| 302 | * <p> |
||
| 303 | * The return value will be casted to boolean if non-boolean was returned. |
||
| 304 | * @since 5.0.0 |
||
| 305 | */ |
||
| 306 | public function offsetExists($offset) { |
||
| 309 | |||
| 310 | /** |
||
| 311 | * Offset to retrieve |
||
| 312 | * @link http://php.net/manual/en/arrayaccess.offsetget.php |
||
| 313 | * |
||
| 314 | * @param mixed $offset <p> |
||
| 315 | * The offset to retrieve. |
||
| 316 | * </p> |
||
| 317 | * |
||
| 318 | * @return mixed Can return all value types. |
||
| 319 | * @since 5.0.0 |
||
| 320 | */ |
||
| 321 | public function offsetGet($offset) { |
||
| 324 | |||
| 325 | /** |
||
| 326 | * Offset to set |
||
| 327 | * @link http://php.net/manual/en/arrayaccess.offsetset.php |
||
| 328 | * |
||
| 329 | * @param mixed $offset <p> |
||
| 330 | * The offset to assign the value to. |
||
| 331 | * </p> |
||
| 332 | * @param mixed $value <p> |
||
| 333 | * The value to set. |
||
| 334 | * </p> |
||
| 335 | * |
||
| 336 | * @return void |
||
| 337 | * @since 5.0.0 |
||
| 338 | */ |
||
| 339 | public function offsetSet($offset, $value) { |
||
| 342 | |||
| 343 | /** |
||
| 344 | * Offset to unset |
||
| 345 | * @link http://php.net/manual/en/arrayaccess.offsetunset.php |
||
| 346 | * |
||
| 347 | * @param mixed $offset <p> |
||
| 348 | * The offset to unset. |
||
| 349 | * </p> |
||
| 350 | * |
||
| 351 | * @return void |
||
| 352 | * @since 5.0.0 |
||
| 353 | */ |
||
| 354 | public function offsetUnset($offset) { |
||
| 357 | |||
| 358 | } |
||
| 359 |
The break statement is not necessary if it is preceded for example by a return statement:
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.