Complex classes like AdminPageFramework_Debug 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 AdminPageFramework_Debug, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 23 | class AdminPageFramework_Debug extends AdminPageFramework_FrameworkUtility { |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Prints out the given variable contents |
||
| 27 | * |
||
| 28 | * If a file pass is given to the second parameter, it saves the output in the file. |
||
| 29 | * |
||
| 30 | * @since 3.2.0 |
||
| 31 | * @remark An alias of the dumpArray() method. |
||
| 32 | * @param array|string $asArray The variable to check its contents. |
||
| 33 | * @param string $sFilePath The file path for a log file. |
||
| 34 | * @return void |
||
| 35 | */ |
||
| 36 | static public function dump( $asArray, $sFilePath=null ) { |
||
| 39 | /** |
||
| 40 | * Prints out the given variable contents. |
||
| 41 | * |
||
| 42 | * If a file pass is given, it saves the output in the file. |
||
| 43 | * |
||
| 44 | * @since unknown |
||
| 45 | * @deprecated 3.2.0 |
||
| 46 | */ |
||
| 47 | static public function dumpArray( $asArray, $sFilePath=null ) { |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Returns a string representation of a given value with details. |
||
| 53 | * @since 3.8.9 |
||
| 54 | * @return string |
||
| 55 | */ |
||
| 56 | static public function getDetails( $mValue, $bEscape=true ) { |
||
| 66 | /** |
||
| 67 | * @return string |
||
| 68 | * @since 3.8.9 |
||
| 69 | */ |
||
| 70 | static private function _getArrayRepresentationSanitized( $sString ) { |
||
| 88 | /** |
||
| 89 | * Retrieves the output of the given variable contents. |
||
| 90 | * |
||
| 91 | * If a file pass is given to the second parameter, it saves the output in the file. |
||
| 92 | * |
||
| 93 | * @remark An alias of getArray() method. |
||
| 94 | * @since 3.2.0 |
||
| 95 | * @param array|string $asArray The variable to check its contents. |
||
| 96 | * @param string $sFilePath The file path for a log file. |
||
| 97 | * @param boolean $bEscape Whether to escape characters. |
||
| 98 | */ |
||
| 99 | static public function get( $asArray, $sFilePath=null, $bEscape=true ) { |
||
| 112 | /** |
||
| 113 | * Retrieves the output of the given array contents. |
||
| 114 | * |
||
| 115 | * If a file pass is given, it saves the output in the file. |
||
| 116 | * |
||
| 117 | * @since 2.1.6 The $bEncloseInTag parameter is added. |
||
| 118 | * @since 3.0.0 Changed the $bEncloseInTag parameter to bEscape. |
||
| 119 | * @deprecated 3.2.0 |
||
| 120 | */ |
||
| 121 | static public function getArray( $asArray, $sFilePath=null, $bEscape=true ) { |
||
| 125 | |||
| 126 | /** |
||
| 127 | * Logs the given variable output to a file. |
||
| 128 | * |
||
| 129 | * <h4>Example</h4> |
||
| 130 | * <code> |
||
| 131 | * $_aValues = array( 'foo', 'bar' ); |
||
| 132 | * AdminPageFramework_Debug::log( $aValues ); |
||
| 133 | * </code> |
||
| 134 | * |
||
| 135 | * @remark The alias of the `logArray()` method. |
||
| 136 | * @since 3.1.0 |
||
| 137 | * @since 3.1.3 Made it leave milliseconds and elapsed time from the last call of the method. |
||
| 138 | * @since 3.3.0 Made it indicate the data type. |
||
| 139 | * @since 3.3.1 Made it indicate the data length. |
||
| 140 | * @param mixed $mValue The value to log. |
||
| 141 | * @param string $sFilePath The log file path. |
||
| 142 | * @return void |
||
| 143 | **/ |
||
| 144 | static public function log( $mValue, $sFilePath=null ) { |
||
| 176 | /** |
||
| 177 | * Determines the log file path. |
||
| 178 | * @since 3.5.3 |
||
| 179 | * @internal |
||
| 180 | * @return string The path of the file to log the contents. |
||
| 181 | */ |
||
| 182 | static private function _getLogFilePath( $bsFilePath, $sCallerClass ) { |
||
| 195 | /** |
||
| 196 | * Creates a file. |
||
| 197 | * @return boolean |
||
| 198 | * @internal |
||
| 199 | */ |
||
| 200 | static private function _createFile( $sFilePath ) { |
||
| 211 | |||
| 212 | /** |
||
| 213 | * Returns the heading part of a log item. |
||
| 214 | * @since 3.5.3 |
||
| 215 | * @internal |
||
| 216 | * @return string the heading part of a log item. |
||
| 217 | */ |
||
| 218 | static private function _getLogHeadingLine( $fCurrentTimeStamp, $nElapsed, $sCallerClass, $sCallerFunction ) { |
||
| 244 | /** |
||
| 245 | * Returns formatted elapsed time. |
||
| 246 | * @since 3.5.3 |
||
| 247 | * @internal |
||
| 248 | * @return string Formatted elapsed time. |
||
| 249 | */ |
||
| 250 | static private function _getFormattedElapsedTime( $nElapsed ) { |
||
| 273 | /** |
||
| 274 | * Logs the given array output into the given file. |
||
| 275 | * |
||
| 276 | * @since 2.1.1 |
||
| 277 | * @since 3.0.3 Changed the default log location and file name. |
||
| 278 | * @deprecated 3.1.0 Use the `log()` method instead. |
||
| 279 | */ |
||
| 280 | static public function logArray( $asArray, $sFilePath=null ) { |
||
| 284 | |||
| 285 | /** |
||
| 286 | * Returns a string representation of the given value. |
||
| 287 | * @since 3.5.0 |
||
| 288 | * @param mixed $mValue The value to get as a string |
||
| 289 | * @internal |
||
| 290 | */ |
||
| 291 | static public function getAsString( $mValue ) { |
||
| 308 | /** |
||
| 309 | * Returns a object name if it is an object. Otherwise, the value itself. |
||
| 310 | * This is used to convert objects into a string in array-walk functions |
||
| 311 | * as objects tent to get large when they are converted to a string representation. |
||
| 312 | * @since 3.8.9 |
||
| 313 | */ |
||
| 314 | static private function _getObjectName( $mItem ) { |
||
| 320 | |||
| 321 | /** |
||
| 322 | * Returns a legible value representation. |
||
| 323 | * @since 3.8.9 |
||
| 324 | * @return string |
||
| 325 | */ |
||
| 326 | static private function _getLegible( $mValue ) { |
||
| 333 | |||
| 334 | /** |
||
| 335 | * @since 3.8.9 |
||
| 336 | * @param callable $asoCallable |
||
| 337 | * @return string |
||
| 338 | */ |
||
| 339 | static private function _getLegibleCallable( $asoCallable ) { |
||
| 354 | /** |
||
| 355 | * @since 3.8.9 |
||
| 356 | * @param object $oObject |
||
| 357 | * @return string |
||
| 358 | */ |
||
| 359 | static public function _getLegibleObject( $oObject ) { |
||
| 368 | /** |
||
| 369 | * Returns an array representation with value types in each element. |
||
| 370 | * The element deeper than 10 dimensions will be dropped. |
||
| 371 | * @since 3.8.9 |
||
| 372 | * @return array |
||
| 373 | */ |
||
| 374 | static public function _getLegibleArray( array $aArray ) { |
||
| 380 | /** |
||
| 381 | * @since 3.8.9 |
||
| 382 | * @return string |
||
| 383 | */ |
||
| 384 | static private function _getLegibleValue( $mItem ) { |
||
| 392 | /** |
||
| 393 | * @since 3.8.9 |
||
| 394 | * @return string |
||
| 395 | */ |
||
| 396 | static private function _getLegibleNonScalar( $mNonScalar ) { |
||
| 411 | /** |
||
| 412 | * @return string |
||
| 413 | * @param scalar $sScalar |
||
| 414 | * @param integer $iCharLimit Character length limit to truncate. |
||
| 415 | * @since 3.8.9 |
||
| 416 | */ |
||
| 417 | static private function _getLegibleScalar( $sScalar ) { |
||
| 426 | /** |
||
| 427 | * Returns a length of a value. |
||
| 428 | * @since 3.5.3 |
||
| 429 | * @internal |
||
| 430 | * @return integer|null For string or integer, the string length. For array, the element lengths. For other types, null. |
||
| 431 | */ |
||
| 432 | static private function _getValueLength( $mValue ) { |
||
| 443 | /** |
||
| 444 | * @return string |
||
| 445 | */ |
||
| 446 | static private function _getLegibleString( $sString, $iCharLimit=200 ) { |
||
| 460 | |||
| 461 | /** |
||
| 462 | * Slices an array by the given depth. |
||
| 463 | * |
||
| 464 | * @since 3.4.4 |
||
| 465 | * @since 3.8.9 Changed it not to convert an object into an array. Changed the scope to private. |
||
| 466 | * @return array |
||
| 467 | * @internal |
||
| 468 | */ |
||
| 469 | static private function _getSliceByDepth( array $aSubject, $iDepth=0 ) { |
||
| 485 | |||
| 486 | /** |
||
| 487 | * Performs `array_map()` recursively. |
||
| 488 | * @return array. |
||
| 489 | * @since 3.8.9 |
||
| 490 | */ |
||
| 491 | static private function _getArrayMappedRecursive( array $aArray, $oCallable ) { |
||
| 499 | static private $_oCurrentCallableForArrayMapRecursive; |
||
| 500 | /** |
||
| 501 | * @internal |
||
| 502 | * @return mixed A modified value. |
||
| 503 | * @since 3.8.9 |
||
| 504 | */ |
||
| 505 | static private function _getArrayMappedNested( $mItem ) { |
||
| 510 | |||
| 511 | } |
||
| 512 |