Complex classes like AdminPageFramework_Debug_Base 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_Base, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 19 | class AdminPageFramework_Debug_Base extends AdminPageFramework_FrameworkUtility { |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var int |
||
| 23 | * @since 3.8.19 |
||
| 24 | */ |
||
| 25 | static public $iLegibleArrayDepthLimit = 50; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Character length limit to truncate. |
||
| 29 | */ |
||
| 30 | static public $iLegibleStringCharacterLimit = 99999; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Returns a legible value representation with value details. |
||
| 34 | * @since 3.8.9 |
||
| 35 | * @return string |
||
| 36 | */ |
||
| 37 | static protected function _getLegibleDetails( $mValue, $iStringLengthLimit=0, $iArrayDepthLimit=0 ) { |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Returns a string representation of the given value with no variable details. |
||
| 47 | * |
||
| 48 | * @since 3.8.9 |
||
| 49 | * @since 3.8.22 Added the `$sStringLengthLimit` and `$iArrayDepthLimit` parameters. |
||
| 50 | * @return string |
||
| 51 | */ |
||
| 52 | static protected function _getLegible( $mValue, $iStringLengthLimit=0, $iArrayDepthLimit=0 ) { |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Returns a object name if it is an object. Otherwise, the value itself. |
||
| 77 | * This is used to convert objects into a string in array-walk functions |
||
| 78 | * as objects tent to get large when they are converted to a string representation. |
||
| 79 | * @since 3.8.9 |
||
| 80 | */ |
||
| 81 | static private function ___getObjectName( $mItem ) { |
||
| 87 | |||
| 88 | /** |
||
| 89 | * @since 3.8.9 |
||
| 90 | * @param callable $asoCallable |
||
| 91 | * @return string |
||
| 92 | */ |
||
| 93 | static private function ___getLegibleDetailedCallable( $asoCallable ) { |
||
| 96 | /** |
||
| 97 | * @since 3.8.9 |
||
| 98 | * @param callable $asoCallable |
||
| 99 | * @return string |
||
| 100 | */ |
||
| 101 | static public function ___getCallableName( $asoCallable ) { |
||
| 115 | |||
| 116 | /** |
||
| 117 | * @since 3.8.9 |
||
| 118 | * @param object $oObject |
||
| 119 | * @return string |
||
| 120 | */ |
||
| 121 | static private function ___getLegibleDetailedObject( $oObject ) { |
||
| 129 | /** |
||
| 130 | * Returns an array representation with value types in each element. |
||
| 131 | * The element deeper than 10 dimensions will be dropped. |
||
| 132 | * @since 3.8.9 |
||
| 133 | * @since 3.8.22 Added the `$iDepthLimit` parameter |
||
| 134 | * @since 3.8.22 Changed the scope to private from public. |
||
| 135 | * @since 3.8.22 Renamed from `_getLegibleArray()`. |
||
| 136 | * @return array |
||
| 137 | */ |
||
| 138 | static private function ___getLegibleDetailedArray( array $aArray, $iStringLengthLimit=0, $iDepthLimit=0 ) { |
||
| 146 | /** |
||
| 147 | * @since 3.8.9 |
||
| 148 | * @since 3.8.22 Renamed from `_getLegibleValue()`. |
||
| 149 | * @return string |
||
| 150 | */ |
||
| 151 | static private function ___getLegibleDetailedValue( $mItem, $iStringLengthLimit ) { |
||
| 159 | /** |
||
| 160 | * @since 3.8.9 |
||
| 161 | * @since 3.8.22 Renamed from `_getLegibleNonScalar()`. |
||
| 162 | * @return string |
||
| 163 | */ |
||
| 164 | static private function ___getLegibleDetailedNonScalar( $mNonScalar ) { |
||
| 179 | /** |
||
| 180 | * @return string |
||
| 181 | * @param integer|float|boolean $sScalar |
||
| 182 | * @param integer $iStringLengthLimit |
||
| 183 | * @since 3.8.9 |
||
| 184 | * @since 3.8.22 Renamed from `_getLegibleScalar()`. |
||
| 185 | */ |
||
| 186 | static private function ___getLegibleDetailedScalar( $sScalar, $iStringLengthLimit ) { |
||
| 194 | /** |
||
| 195 | * Returns a length of a value. |
||
| 196 | * @since 3.5.3 |
||
| 197 | * @internal |
||
| 198 | * @return integer|null For string or integer, the string length. For array, the element lengths. For other types, null. |
||
| 199 | */ |
||
| 200 | static private function ___getValueLength( $mValue ) { |
||
| 210 | /** |
||
| 211 | * @param string $sString |
||
| 212 | * @param integer $iLengthLimit |
||
| 213 | * @param boolean $bShowDetails |
||
| 214 | * @return string |
||
| 215 | */ |
||
| 216 | static private function ___getLegibleString( $sString, $iLengthLimit, $bShowDetails=true ) { |
||
| 236 | |||
| 237 | |||
| 238 | |||
| 239 | |||
| 240 | /** |
||
| 241 | * @return string |
||
| 242 | * @since 3.8.9 |
||
| 243 | */ |
||
| 244 | static protected function _getArrayRepresentationSanitized( $sString ) { |
||
| 262 | |||
| 263 | /** |
||
| 264 | * Slices an array by the given depth. |
||
| 265 | * @return array |
||
| 266 | * @since 3.8.22 |
||
| 267 | */ |
||
| 268 | static public function getSlicedByDepth( array $aSubject, $iDepth=0, $sMore='(array truncated) ...' ) { |
||
| 271 | |||
| 272 | /** |
||
| 273 | * Slices an array by the given depth. |
||
| 274 | * |
||
| 275 | * @param array $aSubject |
||
| 276 | * @param int $iDepth |
||
| 277 | * @param string $sMore |
||
| 278 | * |
||
| 279 | * @return array |
||
| 280 | * @since 3.4.4 |
||
| 281 | * @since 3.8.9 Changed it not to convert an object into an array. |
||
| 282 | * @since 3.8.9 Changed the scope to private. |
||
| 283 | * @since 3.8.9 Renamed from `getSliceByDepth()`. |
||
| 284 | * @since 3.8.22 Show a message when truncated by depth. |
||
| 285 | * @since 3.8.22 Added the `$sMore` parameter. |
||
| 286 | * @internal |
||
| 287 | */ |
||
| 288 | static private function _getSlicedByDepth( array $aSubject, $iDepth=0, $sMore='(array truncated) ...' ) { |
||
| 313 | |||
| 314 | /** |
||
| 315 | * Performs `array_map()` recursively. |
||
| 316 | * @remark Accepts arguments. |
||
| 317 | * @return array |
||
| 318 | * @since 3.8.9 |
||
| 319 | */ |
||
| 320 | static private function ___getArrayMappedRecursive( array $aArray, $oCallable, array $aArguments=array() ) { |
||
| 330 | static private $___oCurrentCallableForArrayMapRecursive; |
||
| 331 | static private $___aArgumentsForArrayMapRecursive; |
||
| 332 | /** |
||
| 333 | * @internal |
||
| 334 | * @return mixed A modified value. |
||
| 335 | * @since 3.8.9 |
||
| 336 | */ |
||
| 337 | static private function ___getArrayMappedNested( $mItem ) { |
||
| 345 | |||
| 346 | /** |
||
| 347 | * @param Exception $oException |
||
| 348 | * @param integer $iSkip The number of skipping records. This is used when the caller does not want to include the self function/method. |
||
| 349 | * |
||
| 350 | * @return string |
||
| 351 | * @since 3.8.22 |
||
| 352 | */ |
||
| 353 | static public function getStackTrace( Exception $oException, $iSkip=0 ) { |
||
| 378 | /** |
||
| 379 | * @param array $aTraceArguments |
||
| 380 | * @return string |
||
| 381 | * @since 3.8.22 |
||
| 382 | * @internal |
||
| 383 | */ |
||
| 384 | static private function ___getArgumentsOfEachStackTrace( array $aTraceArguments ) { |
||
| 401 | /** |
||
| 402 | * @since 3.8.22 |
||
| 403 | * @param mixed $mArgument |
||
| 404 | * @internal |
||
| 405 | * @return string |
||
| 406 | */ |
||
| 407 | static private function ___getStackTraceArgument_string( $mArgument ) { |
||
| 451 | |||
| 452 | } |
||
| 453 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.