Complex classes like CallableDir 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 CallableDir, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 27 | class CallableDir extends RequestPlugin |
||
| 28 | { |
||
| 29 | use \Jaxon\Utils\Traits\Config; |
||
| 30 | use \Jaxon\Utils\Traits\Manager; |
||
| 31 | use \Jaxon\Utils\Traits\Validator; |
||
| 32 | use \Jaxon\Utils\Traits\Translator; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * The registered callable objects |
||
| 36 | * |
||
| 37 | * @var array |
||
| 38 | */ |
||
| 39 | protected $aCallableDirs = []; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * True if the Composer autoload is enabled |
||
| 43 | * |
||
| 44 | * @var boolean |
||
| 45 | */ |
||
| 46 | private $bAutoloadEnabled = true; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * The Composer autoloader |
||
| 50 | * |
||
| 51 | * @var Autoloader |
||
| 52 | */ |
||
| 53 | private $xAutoloader = null; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Return the name of this plugin |
||
| 57 | * |
||
| 58 | * @return string |
||
| 59 | */ |
||
| 60 | public function getName() |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Use the Composer autoloader |
||
| 67 | * |
||
| 68 | * @return void |
||
| 69 | */ |
||
| 70 | public function useComposerAutoloader() |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Disable the autoloader in the library |
||
| 78 | * |
||
| 79 | * The user shall provide an alternative autoload system. |
||
| 80 | * |
||
| 81 | * @return void |
||
| 82 | */ |
||
| 83 | public function disableAutoload() |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Register a callable class |
||
| 91 | * |
||
| 92 | * @param string $sType The type of request handler being registered |
||
| 93 | * @param string $sDirectory The name of the class being registered |
||
| 94 | * @param array|string $aOptions The associated options |
||
| 95 | * |
||
| 96 | * @return boolean |
||
| 97 | */ |
||
| 98 | public function register($sType, $sDirectory, $aOptions) |
||
| 177 | |||
| 178 | /** |
||
| 179 | * Register an instance of a given class from a file |
||
| 180 | * |
||
| 181 | * @param object $xFile The PHP file containing the class |
||
| 182 | * @param string $sDirectory The path to the directory |
||
| 183 | * @param string|'' $sNamespace The associated namespace |
||
|
|
|||
| 184 | * @param string $sSeparator The character to use as separator in javascript class names |
||
| 185 | * @param array $aProtected The functions that are not to be exported |
||
| 186 | * @param array $aOptions The options to register the class with |
||
| 187 | * |
||
| 188 | * @return void |
||
| 189 | */ |
||
| 190 | protected function _registerClass($xFile, $sDirectory, $sNamespace = '', $sSeparator = '.', |
||
| 231 | |||
| 232 | /** |
||
| 233 | * Register callable objects from all class directories |
||
| 234 | * |
||
| 235 | * @param array $aOptions The options to register the classes with |
||
| 236 | * |
||
| 237 | * @return void |
||
| 238 | */ |
||
| 239 | public function registerClasses(array $aOptions = []) |
||
| 293 | |||
| 294 | /** |
||
| 295 | * Generate a hash for the registered callable objects |
||
| 296 | * |
||
| 297 | * @return string |
||
| 298 | */ |
||
| 299 | public function generateHash() |
||
| 312 | |||
| 313 | /** |
||
| 314 | * Generate client side javascript code for the registered callable objects |
||
| 315 | * |
||
| 316 | * @return string |
||
| 317 | */ |
||
| 318 | public function getScript() |
||
| 323 | |||
| 324 | /** |
||
| 325 | * Check if this plugin can process the incoming Jaxon request |
||
| 326 | * |
||
| 327 | * @return boolean |
||
| 328 | */ |
||
| 329 | public function canProcessRequest() |
||
| 334 | |||
| 335 | /** |
||
| 336 | * Process the incoming Jaxon request |
||
| 337 | * |
||
| 338 | * @return boolean |
||
| 339 | */ |
||
| 340 | public function processRequest() |
||
| 344 | } |
||
| 345 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.