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 | * Retrieves the output of the given variable contents. |
||
| 53 | * |
||
| 54 | * If a file pass is given to the second parameter, it saves the output in the file. |
||
| 55 | * |
||
| 56 | * @remark An alias of getArray() method. |
||
| 57 | * @since 3.2.0 |
||
| 58 | * @param array|string $asArray The variable to check its contents. |
||
| 59 | * @param string $sFilePath The file path for a log file. |
||
| 60 | * @param boolean $bEscape Whether to escape characters. |
||
| 61 | */ |
||
| 62 | static public function get( $asArray, $sFilePath=null, $bEscape=true ) { |
||
| 75 | /** |
||
| 76 | * Retrieves the output of the given array contents. |
||
| 77 | * |
||
| 78 | * If a file pass is given, it saves the output in the file. |
||
| 79 | * |
||
| 80 | * @since 2.1.6 The $bEncloseInTag parameter is added. |
||
| 81 | * @since 3.0.0 Changed the $bEncloseInTag parameter to bEscape. |
||
| 82 | * @deprecated 3.2.0 |
||
| 83 | */ |
||
| 84 | static public function getArray( $asArray, $sFilePath=null, $bEscape=true ) { |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Logs the given variable output to a file. |
||
| 91 | * |
||
| 92 | * <h4>Example</h4> |
||
| 93 | * <code> |
||
| 94 | * $_aValues = array( 'foo', 'bar' ); |
||
| 95 | * AdminPageFramework_Debug::log( $aValues ); |
||
| 96 | * </code> |
||
| 97 | * |
||
| 98 | * @remark The alias of the `logArray()` method. |
||
| 99 | * @since 3.1.0 |
||
| 100 | * @since 3.1.3 Made it leave milliseconds and elapsed time from the last call of the method. |
||
| 101 | * @since 3.3.0 Made it indicate the data type. |
||
| 102 | * @since 3.3.1 Made it indicate the data length. |
||
| 103 | * @param mixed $mValue The value to log. |
||
| 104 | * @param string $sFilePath The log file path. |
||
| 105 | * @return void |
||
| 106 | **/ |
||
| 107 | static public function log( $mValue, $sFilePath=null ) { |
||
| 139 | /** |
||
| 140 | * Determines the log file path. |
||
| 141 | * @since 3.5.3 |
||
| 142 | * @internal |
||
| 143 | * @return string The path of the file to log the contents. |
||
| 144 | */ |
||
| 145 | static private function _getLogFilePath( $bsFilePath, $sCallerClass ) { |
||
| 158 | /** |
||
| 159 | * Creates a file. |
||
| 160 | * @return boolean |
||
| 161 | * @internal |
||
| 162 | */ |
||
| 163 | static private function _createFile( $sFilePath ) { |
||
| 174 | |||
| 175 | /** |
||
| 176 | * Returns the log contents. |
||
| 177 | * @internal |
||
| 178 | * @since 3.5.3 |
||
| 179 | * @param mixed $mValue The value to log. |
||
| 180 | */ |
||
| 181 | static private function _getLogContents( $mValue ) { |
||
| 193 | /** |
||
| 194 | * Returns a length of a value. |
||
| 195 | * @since 3.5.3 |
||
| 196 | * @internal |
||
| 197 | * @return integer|null For string or integer, the string length. For array, the element lengths. For other types, null. |
||
| 198 | */ |
||
| 199 | static private function _getValueLength( $mValue, $sVariableType ) { |
||
| 210 | /** |
||
| 211 | * Returns the heading part of a log item. |
||
| 212 | * @since 3.5.3 |
||
| 213 | * @internal |
||
| 214 | * @return string the heading part of a log item. |
||
| 215 | */ |
||
| 216 | static private function _getLogHeadingLine( $fCurrentTimeStamp, $nElapsed, $sCallerClass, $sCallerFunction ) { |
||
| 242 | /** |
||
| 243 | * Returns formatted elapsed time. |
||
| 244 | * @since 3.5.3 |
||
| 245 | * @internal |
||
| 246 | * @return string Formatted elapsed time. |
||
| 247 | */ |
||
| 248 | static private function _getFormattedElapsedTime( $nElapsed ) { |
||
| 271 | /** |
||
| 272 | * Logs the given array output into the given file. |
||
| 273 | * |
||
| 274 | * @since 2.1.1 |
||
| 275 | * @since 3.0.3 Changed the default log location and file name. |
||
| 276 | * @deprecated 3.1.0 Use the `log()` method instead. |
||
| 277 | */ |
||
| 278 | static public function logArray( $asArray, $sFilePath=null ) { |
||
| 282 | |||
| 283 | /** |
||
| 284 | * Returns a string representation of the given value. |
||
| 285 | * @since 3.5.0 |
||
| 286 | * @param mixed $mValue The value to get as a string |
||
| 287 | * @internal |
||
| 288 | */ |
||
| 289 | static public function getAsString( $mValue ) { |
||
| 297 | /** |
||
| 298 | * @since 3.8.9 |
||
| 299 | * @return mixed |
||
| 300 | */ |
||
| 301 | static private function _getLegibleCallable( $asoCallable ) { |
||
| 319 | |||
| 320 | /** |
||
| 321 | * @since 3.8.9 |
||
| 322 | * @return mixed |
||
| 323 | */ |
||
| 324 | static public function _getLegibleObject( $oObject ) { |
||
| 338 | |||
| 339 | /** |
||
| 340 | * @since 3.8.9 |
||
| 341 | * @return mixed |
||
| 342 | */ |
||
| 343 | static public function _getLegibleArray( $aArray ) { |
||
| 354 | |||
| 355 | /** |
||
| 356 | * Slices the given array by depth. |
||
| 357 | * |
||
| 358 | * @since 3.4.4 |
||
| 359 | * @since 3.8.9 Changed it not to convert an object into an array. |
||
| 360 | * @return array |
||
| 361 | * @internal |
||
| 362 | */ |
||
| 363 | static public function getSliceByDepth( array $aSubject, $iDepth=0 ) { |
||
| 379 | |||
| 380 | /** |
||
| 381 | * @return string |
||
| 382 | * @since 3.8.9 |
||
| 383 | */ |
||
| 384 | static private function _getLegibleValue( $mItem ) { |
||
| 399 | /** |
||
| 400 | * @return string |
||
| 401 | * @since 3.8.9 |
||
| 402 | */ |
||
| 403 | static private function _getLegibleString( $sScalar, $iCharLimit=300 ) { |
||
| 419 | /** |
||
| 420 | * Performs `array_map()` recursively. |
||
| 421 | * @return array. |
||
| 422 | * @since 3.8.9 |
||
| 423 | */ |
||
| 424 | static private function _getArrayMappedRecursive( array $aArray, $oCallable ) { |
||
| 432 | static public $oCurrentCallable; |
||
| 433 | /** |
||
| 434 | * @internal |
||
| 435 | * @return mixed A modified value. |
||
| 436 | * @since 3.8.9 |
||
| 437 | */ |
||
| 438 | static private function _getArrayMappedNested( $mItem ) { |
||
| 443 | |||
| 444 | } |
||
| 445 |