Complex classes like XmppClient 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 XmppClient, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 66 | class XmppClient extends XmlStream implements ContainerInterface |
||
| 67 | { |
||
| 68 | use ServiceManager, Accessors; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Connector used to instantiate stream connection to server. |
||
| 72 | * |
||
| 73 | * @var Connector |
||
| 74 | */ |
||
| 75 | private $_connector; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Client's jid (Jabber Identifier) address. |
||
| 79 | * |
||
| 80 | * @var Jid |
||
| 81 | */ |
||
| 82 | private $_jid; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Dependency container used as service manager. |
||
| 86 | * |
||
| 87 | * @var Container |
||
| 88 | */ |
||
| 89 | private $_container; |
||
| 90 | |||
| 91 | /** |
||
| 92 | * Features provided by that stream |
||
| 93 | * |
||
| 94 | * @var Features |
||
| 95 | */ |
||
| 96 | private $_features; |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Current client state. |
||
| 100 | * |
||
| 101 | * @var string |
||
| 102 | */ |
||
| 103 | private $_state = 'disconnected'; |
||
| 104 | private $_lang; |
||
| 105 | |||
| 106 | /** |
||
| 107 | * XmppClient constructor. |
||
| 108 | * @param Jid $jid |
||
| 109 | * @param array $options { |
||
| 110 | * @var XmlParser $parser Parser used for interpreting streams. |
||
| 111 | * @var Component[] $modules Additional modules registered when creating client. |
||
| 112 | * @var string $language Stream language (reflects xml:language attribute) |
||
| 113 | * @var ContainerInterface $container Dependency container used for module management. |
||
| 114 | * @var bool $default -modules Load default modules or not |
||
| 115 | * } |
||
| 116 | */ |
||
| 117 | public function __construct(Jid $jid, array $options = []) |
||
| 144 | |||
| 145 | public function applyOptions(array $options) |
||
| 167 | |||
| 168 | public function start(array $attributes = []) |
||
| 176 | |||
| 177 | public function connect() |
||
| 183 | |||
| 184 | public function bind($jid) |
||
| 198 | |||
| 199 | /** |
||
| 200 | * Registers module in client's dependency container. |
||
| 201 | * |
||
| 202 | * @param ComponentInterface $module Module to be registered |
||
| 203 | * @param bool|string|array $alias Module alias, class name by default. |
||
| 204 | * `true` for aliasing interfaces and parents too, |
||
| 205 | * `false` for aliasing as class name only |
||
| 206 | * array for multiple aliases, |
||
| 207 | * and any string for alias name |
||
| 208 | */ |
||
| 209 | public function register(ComponentInterface $module, $alias = true) |
||
| 222 | |||
| 223 | private function _addToContainer(ComponentInterface $module, array $aliases) { |
||
| 230 | |||
| 231 | /** |
||
| 232 | * Sends stanza to server and returns promise with server response. |
||
| 233 | * |
||
| 234 | * @param Stanza $stanza |
||
| 235 | * @return ExtendedPromiseInterface |
||
| 236 | */ |
||
| 237 | public function send(Stanza $stanza) : ExtendedPromiseInterface |
||
| 252 | |||
| 253 | private function handleConnect($stream) |
||
| 267 | |||
| 268 | //region Features |
||
| 269 | public function getFeatures() |
||
| 273 | //endregion |
||
| 274 | |||
| 275 | //region Parser |
||
| 276 | public function setParser(XmlParser $parser) |
||
| 285 | |||
| 286 | public function getParser() |
||
| 290 | //endregion |
||
| 291 | |||
| 292 | //region Connector |
||
| 293 | protected function setConnector($connector) |
||
| 310 | |||
| 311 | public function getConnector() |
||
| 315 | //endregion |
||
| 316 | |||
| 317 | //region Resource |
||
| 318 | public function setResource(string $resource) |
||
| 322 | |||
| 323 | public function getResource() |
||
| 327 | //endregion |
||
| 328 | |||
| 329 | //region Password |
||
| 330 | public function setPassword(string $password) |
||
| 334 | |||
| 335 | public function getPassword() |
||
| 339 | //endregion |
||
| 340 | |||
| 341 | //region Modules |
||
| 342 | public function setModules(array $modules) |
||
| 348 | //endregion |
||
| 349 | |||
| 350 | //region State |
||
| 351 | public function setState($state) |
||
| 356 | |||
| 357 | public function getState() |
||
| 361 | //endregion |
||
| 362 | |||
| 363 | //region Container |
||
| 364 | protected function getContainer() : ContainerInterface |
||
| 368 | |||
| 369 | protected function setContainer(Container $container) |
||
| 373 | //endregion |
||
| 374 | |||
| 375 | //region Language |
||
| 376 | public function getLanguage(): string |
||
| 380 | |||
| 381 | public function setLanguage(string $language) |
||
| 385 | //endregion |
||
| 386 | |||
| 387 | //region JID |
||
| 388 | public function getJid() |
||
| 392 | |||
| 393 | protected function setJid(Jid $jid) |
||
| 397 | //endregion |
||
| 398 | } |
||
| 399 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.