Complex classes like CallableClass 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 CallableClass, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 32 | class CallableClass extends RequestPlugin |
||
| 33 | { |
||
| 34 | use \Jaxon\Features\Config; |
||
| 35 | use \Jaxon\Features\Template; |
||
| 36 | use \Jaxon\Features\Validator; |
||
| 37 | use \Jaxon\Features\Translator; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * The callable registrar |
||
| 41 | * |
||
| 42 | * @var CallableRegistry |
||
| 43 | */ |
||
| 44 | protected $xRegistry; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * The callable repository |
||
| 48 | * |
||
| 49 | * @var CallableRepository |
||
| 50 | */ |
||
| 51 | protected $xRepository; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * The value of the class parameter of the incoming Jaxon request |
||
| 55 | * |
||
| 56 | * @var string |
||
| 57 | */ |
||
| 58 | protected $sRequestedClass = ''; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * The value of the method parameter of the incoming Jaxon request |
||
| 62 | * |
||
| 63 | * @var string |
||
| 64 | */ |
||
| 65 | protected $sRequestedMethod = ''; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * The class constructor |
||
| 69 | * |
||
| 70 | * @param CallableRegistry $xRegistry The callable class registry |
||
| 71 | * @param CallableRepository $xRepository The callable object repository |
||
| 72 | */ |
||
| 73 | public function __construct(CallableRegistry $xRegistry, CallableRepository $xRepository) |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Return the name of this plugin |
||
| 98 | * |
||
| 99 | * @return string |
||
| 100 | */ |
||
| 101 | public function getName() |
||
| 105 | |||
| 106 | /** |
||
| 107 | * Return the target class and method |
||
| 108 | * |
||
| 109 | * @return Target|null |
||
| 110 | */ |
||
| 111 | public function getTarget() |
||
| 119 | |||
| 120 | /** |
||
| 121 | * Register a callable class |
||
| 122 | * |
||
| 123 | * @param string $sType The type of request handler being registered |
||
| 124 | * @param string $sClassName The name of the class being registered |
||
| 125 | * @param array|string $aOptions The associated options |
||
| 126 | * |
||
| 127 | * @return boolean |
||
| 128 | */ |
||
| 129 | public function register($sType, $sClassName, $aOptions) |
||
| 154 | |||
| 155 | /** |
||
| 156 | * Generate a hash for the registered callable objects |
||
| 157 | * |
||
| 158 | * @return string |
||
| 159 | */ |
||
| 160 | public function generateHash() |
||
| 178 | |||
| 179 | /** |
||
| 180 | * Generate client side javascript code for namespaces |
||
| 181 | * |
||
| 182 | * @return string |
||
| 183 | */ |
||
| 184 | private function getNamespacesScript() |
||
| 209 | |||
| 210 | /** |
||
| 211 | * Generate client side javascript code for a callable class |
||
| 212 | * |
||
| 213 | * @param string $sClassName The class name |
||
| 214 | * @param CallableObject $xCallableObject The corresponding callable object |
||
| 215 | * @param array $aProtectedMethods The protected methods |
||
| 216 | * |
||
| 217 | * @return string |
||
| 218 | */ |
||
| 219 | private function getCallableScript($sClassName, CallableObject $xCallableObject, array $aProtectedMethods) |
||
| 250 | |||
| 251 | /** |
||
| 252 | * Generate client side javascript code for the registered callable objects |
||
| 253 | * |
||
| 254 | * @return string |
||
| 255 | */ |
||
| 256 | public function getScript() |
||
| 278 | |||
| 279 | /** |
||
| 280 | * Check if this plugin can process the incoming Jaxon request |
||
| 281 | * |
||
| 282 | * @return boolean |
||
| 283 | */ |
||
| 284 | public function canProcessRequest() |
||
| 295 | |||
| 296 | /** |
||
| 297 | * Process the incoming Jaxon request |
||
| 298 | * |
||
| 299 | * @return boolean |
||
| 300 | */ |
||
| 301 | public function processRequest() |
||
| 327 | } |
||
| 328 |