Complex classes like OpenFireRestApi 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 OpenFireRestApi, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 7 | class OpenFireRestApi extends RestClient |
||
| 8 | { |
||
| 9 | |||
| 10 | |||
| 11 | public function __construct() |
||
| 16 | |||
| 17 | |||
| 18 | |||
| 19 | /** |
||
| 20 | * Get all registered users |
||
| 21 | * |
||
| 22 | * @return json|false Json with data or error, or False when something went fully wrong |
||
| 23 | */ |
||
| 24 | public function getUsers($opts = []) |
||
| 33 | |||
| 34 | |||
| 35 | /** |
||
| 36 | * Get information for a specified user |
||
| 37 | * |
||
| 38 | * @return json|false Json with data or error, or False when something went fully wrong |
||
| 39 | */ |
||
| 40 | public function getUser($username) |
||
| 45 | |||
| 46 | |||
| 47 | /** |
||
| 48 | * Creates a new OpenFire user |
||
| 49 | * |
||
| 50 | * @param string $username Username |
||
| 51 | * @param string $password Password |
||
| 52 | * @param string|false $name Name (Optional) |
||
| 53 | * @param string|false $email Email (Optional) |
||
| 54 | * @param string[]|false $groups Groups (Optional) |
||
| 55 | * @return json|false Json with data or error, or False when something went fully wrong |
||
| 56 | */ |
||
| 57 | public function addUser($username, $password, $name=false, $email=false, $groups=false) |
||
| 62 | |||
| 63 | |||
| 64 | /** |
||
| 65 | * Deletes an OpenFire user |
||
| 66 | * |
||
| 67 | * @param string $username Username |
||
| 68 | * @return json|false Json with data or error, or False when something went fully wrong |
||
| 69 | */ |
||
| 70 | public function deleteUser($username) |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Updates an OpenFire user |
||
| 78 | * |
||
| 79 | * @param string $username Username |
||
| 80 | * @param string|false $password Password (Optional) |
||
| 81 | * @param string|false $name Name (Optional) |
||
| 82 | * @param string|false $email Email (Optional) |
||
| 83 | * @param string[]|false $groups Groups (Optional) |
||
| 84 | * @return json|false Json with data or error, or False when something went fully wrong |
||
| 85 | */ |
||
| 86 | public function updateUser($username, $password, $name=false, $email=false, $groups=false) |
||
| 91 | |||
| 92 | |||
| 93 | /** |
||
| 94 | * Retrieve all user groups |
||
| 95 | * |
||
| 96 | * @param string $username Username |
||
| 97 | * @return json|false Json with data or error, or False when something went fully wrong |
||
| 98 | */ |
||
| 99 | public function userGroups($username) |
||
| 104 | |||
| 105 | /** |
||
| 106 | * Add user to groups |
||
| 107 | * |
||
| 108 | * @param string $username Username |
||
| 109 | * @param Array $groups Groups to add user |
||
| 110 | * @return json|false Json with data or error, or False when something went fully wrong |
||
| 111 | */ |
||
| 112 | public function addToGroups($username, $groups) |
||
| 117 | |||
| 118 | /** |
||
| 119 | * Add user to a group |
||
| 120 | * |
||
| 121 | * @param string $username Username |
||
| 122 | * @param string $groups Groups to add user |
||
|
|
|||
| 123 | * @return json|false Json with data or error, or False when something went fully wrong |
||
| 124 | */ |
||
| 125 | public function addToGroup($username, $groupName) |
||
| 130 | |||
| 131 | |||
| 132 | /** |
||
| 133 | * Delete user from a group |
||
| 134 | * |
||
| 135 | * @param string $username Username |
||
| 136 | * @param string $groups Groups to add user |
||
| 137 | * @return json|false Json with data or error, or False when something went fully wrong |
||
| 138 | */ |
||
| 139 | public function deleteFromGroup($username, $groupName) |
||
| 144 | |||
| 145 | |||
| 146 | /** |
||
| 147 | * lockout/Disable an OpenFire user |
||
| 148 | * |
||
| 149 | * @param string $username Username |
||
| 150 | * @return json|false Json with data or error, or False when something went fully wrong |
||
| 151 | */ |
||
| 152 | public function lockoutUser($username) |
||
| 157 | |||
| 158 | |||
| 159 | /** |
||
| 160 | * unlocks an OpenFire user |
||
| 161 | * |
||
| 162 | * @param string $username Username |
||
| 163 | * @return json|false Json with data or error, or False when something went fully wrong |
||
| 164 | */ |
||
| 165 | public function unlockUser($username) |
||
| 170 | |||
| 171 | |||
| 172 | /** |
||
| 173 | * List user rosters |
||
| 174 | * |
||
| 175 | * @param string $username Username |
||
| 176 | * @return json|false Json with data or error, or False when something went fully wrong |
||
| 177 | */ |
||
| 178 | public function userRosters($username) |
||
| 183 | |||
| 184 | |||
| 185 | /** |
||
| 186 | * Adds to this OpenFire user's roster |
||
| 187 | * |
||
| 188 | * @param string $username Username |
||
| 189 | * @param string $jid JID |
||
| 190 | * @param string|false $name Name (Optional) |
||
| 191 | * @param int|false $subscriptionType Subscription (Optional) |
||
| 192 | * @return json|false Json with data or error, or False when something went fully wrong |
||
| 193 | */ |
||
| 194 | public function addToRoster($username, $jid, $name=false, $subscriptionType=false) |
||
| 199 | |||
| 200 | |||
| 201 | /** |
||
| 202 | * Removes from this OpenFire user's roster |
||
| 203 | * |
||
| 204 | * @param string $username Username |
||
| 205 | * @param string $jid JID |
||
| 206 | * @return json|false Json with data or error, or False when something went fully wrong |
||
| 207 | */ |
||
| 208 | public function deleteFromRoster($username, $jid) |
||
| 213 | |||
| 214 | /** |
||
| 215 | * Updates this OpenFire user's roster |
||
| 216 | * |
||
| 217 | * @param string $username Username |
||
| 218 | * @param string $jid JID |
||
| 219 | * @param string|false $nickname Nick Name (Optional) |
||
| 220 | * @param int|false $subscriptionType Subscription (Optional) |
||
| 221 | * @return json|false Json with data or error, or False when something went fully wrong |
||
| 222 | */ |
||
| 223 | public function updateRoster($username, $jid, $nickname=false, $subscriptionType=false) |
||
| 228 | |||
| 229 | |||
| 230 | |||
| 231 | |||
| 232 | /** |
||
| 233 | * Gell all active sessions |
||
| 234 | * |
||
| 235 | * @return json|false Json with data or error, or False when something went fully wrong |
||
| 236 | */ |
||
| 237 | public function getChatRoom($name) |
||
| 241 | |||
| 242 | /** |
||
| 243 | * Gell all chat rooms |
||
| 244 | * |
||
| 245 | * @return json|false Json with data or error, or False when something went fully wrong |
||
| 246 | */ |
||
| 247 | public function getAllChatRooms() |
||
| 251 | |||
| 252 | |||
| 253 | /** |
||
| 254 | * Create a chat room |
||
| 255 | * |
||
| 256 | * @param string $params Params |
||
| 257 | * @return json|false Json with data or error, or False when something went fully wrong |
||
| 258 | */ |
||
| 259 | public function createChatRoom($params = []) |
||
| 263 | |||
| 264 | |||
| 265 | /** |
||
| 266 | * Update a chat room |
||
| 267 | * |
||
| 268 | * @param string $params Params |
||
| 269 | * @return json|false Json with data or error, or False when something went fully wrong |
||
| 270 | */ |
||
| 271 | public function updateChatRoom($roomName, $params = []) |
||
| 275 | |||
| 276 | |||
| 277 | /** |
||
| 278 | * Delete a chat room |
||
| 279 | * |
||
| 280 | * @param string $name Name of the Group to delete |
||
| 281 | * @return json|false Json with data or error, or False when something went fully wrong |
||
| 282 | */ |
||
| 283 | public function deleteChatRoom($roomName) |
||
| 287 | |||
| 288 | /** |
||
| 289 | * Get chat room participants |
||
| 290 | * |
||
| 291 | * @param string $name Name of the chatroom |
||
| 292 | * @return json|false Json with data or error, or False when something went fully wrong |
||
| 293 | */ |
||
| 294 | public function getChatRoomParticipants($roomName) |
||
| 298 | |||
| 299 | /** |
||
| 300 | * Get chat room occupants |
||
| 301 | * |
||
| 302 | * @param string $name Name of the chatroom |
||
| 303 | * @return json|false Json with data or error, or False when something went fully wrong |
||
| 304 | */ |
||
| 305 | public function getChatRoomOccupants($roomName) |
||
| 309 | |||
| 310 | /** |
||
| 311 | * Add user with role to chatroom |
||
| 312 | * |
||
| 313 | * @param string $name Name of the user or jid |
||
| 314 | * @return json|false Json with data or error, or False when something went fully wrong |
||
| 315 | */ |
||
| 316 | public function addUserRoleToChatRoom($roomName, $name, $roles) |
||
| 320 | |||
| 321 | |||
| 322 | /** |
||
| 323 | * Add group with role to chatroom |
||
| 324 | * |
||
| 325 | * @param string $name Name of the group |
||
| 326 | * @return json|false Json with data or error, or False when something went fully wrong |
||
| 327 | */ |
||
| 328 | public function addGroupRoleToChatRoom($roomName, $name, $roles) |
||
| 332 | |||
| 333 | |||
| 334 | /** |
||
| 335 | * Delete a user from a chat room |
||
| 336 | * |
||
| 337 | * @param string $name Name of the group |
||
| 338 | * @return json|false Json with data or error, or False when something went fully wrong |
||
| 339 | */ |
||
| 340 | public function deleteChatRoomUser($roomName, $name, $roles) |
||
| 344 | |||
| 345 | |||
| 346 | /** |
||
| 347 | * Retrieve all system properties |
||
| 348 | * |
||
| 349 | * @return json|false Json with data or error, or False when something went fully wrong |
||
| 350 | */ |
||
| 351 | public function getSystemProperties() |
||
| 355 | |||
| 356 | /** |
||
| 357 | * Retrieve a system property |
||
| 358 | * |
||
| 359 | * @param string $name Name of property |
||
| 360 | * @return json|false Json with data or error, or False when something went fully wrong |
||
| 361 | */ |
||
| 362 | public function getSystemProperty($propertyName) |
||
| 366 | |||
| 367 | |||
| 368 | /** |
||
| 369 | * Create a system property |
||
| 370 | * |
||
| 371 | * @param array $data new property with value |
||
| 372 | * @return json|false Json with data or error, or False when something went fully wrong |
||
| 373 | */ |
||
| 374 | public function createSystemProperty($data) |
||
| 378 | |||
| 379 | |||
| 380 | /** |
||
| 381 | * Update a system property |
||
| 382 | * |
||
| 383 | * @param string $propertyName name of property to update |
||
| 384 | * @param array $data new property with value |
||
| 385 | * @return json|false Json with data or error, or False when something went fully wrong |
||
| 386 | */ |
||
| 387 | public function updateSystemProperty($propertyName, $data) |
||
| 391 | |||
| 392 | |||
| 393 | /** |
||
| 394 | * Delete a system property |
||
| 395 | * |
||
| 396 | * @param array $data new property with value |
||
| 397 | * @return json|false Json with data or error, or False when something went fully wrong |
||
| 398 | */ |
||
| 399 | public function deleteSystemProperty($propertyName) |
||
| 403 | |||
| 404 | |||
| 405 | /** |
||
| 406 | * Retrieve concurrent sessions |
||
| 407 | * |
||
| 408 | * @return json|false Json with data or error, or False when something went fully wrong |
||
| 409 | */ |
||
| 410 | public function getConcurrentSessons() |
||
| 414 | |||
| 415 | |||
| 416 | /** |
||
| 417 | * Get all groups |
||
| 418 | * |
||
| 419 | * @return json|false Json with data or error, or False when something went fully wrong |
||
| 420 | */ |
||
| 421 | public function getGroups() |
||
| 426 | |||
| 427 | /** |
||
| 428 | * Retrieve a group |
||
| 429 | * |
||
| 430 | * @param string $name Name of group |
||
| 431 | * @return json|false Json with data or error, or False when something went fully wrong |
||
| 432 | */ |
||
| 433 | public function getGroup($name) |
||
| 438 | |||
| 439 | /** |
||
| 440 | * Create a group |
||
| 441 | * |
||
| 442 | * @param string $name Name of the group |
||
| 443 | * @param string $description Some description of the group |
||
| 444 | * |
||
| 445 | * @return json|false Json with data or error, or False when something went fully wrong |
||
| 446 | */ |
||
| 447 | public function createGroup($name, $description = false) |
||
| 452 | |||
| 453 | /** |
||
| 454 | * Delete a group |
||
| 455 | * |
||
| 456 | * @param string $name Name of the Group to delete |
||
| 457 | * @return json|false Json with data or error, or False when something went fully wrong |
||
| 458 | */ |
||
| 459 | public function deleteGroup($name) |
||
| 464 | |||
| 465 | /** |
||
| 466 | * Update a group (description) |
||
| 467 | * |
||
| 468 | * @param string $name Name of group |
||
| 469 | * @param string $description Some description of the group |
||
| 470 | * |
||
| 471 | */ |
||
| 472 | public function updateGroup($name, $description) |
||
| 477 | |||
| 478 | |||
| 479 | /** |
||
| 480 | * Retrieve all sessions |
||
| 481 | * |
||
| 482 | * @return json|false Json with data or error, or False when something went fully wrong |
||
| 483 | */ |
||
| 484 | public function getSessions() |
||
| 489 | |||
| 490 | /** |
||
| 491 | * Retrieve all user sessions |
||
| 492 | * |
||
| 493 | * @param string $username Username of user |
||
| 494 | * @return json|false Json with data or error, or False when something went fully wrong |
||
| 495 | */ |
||
| 496 | public function getUserSessions($username) |
||
| 501 | |||
| 502 | |||
| 503 | /** |
||
| 504 | * Close all user sessions |
||
| 505 | * @param string $username Username of user |
||
| 506 | * @return json|false Json with data or error, or False when something went fully wrong |
||
| 507 | */ |
||
| 508 | public function closeUserSessions($username) |
||
| 513 | |||
| 514 | /** |
||
| 515 | * Send a broadcast message to all online users |
||
| 516 | * |
||
| 517 | * @param string $content message to send |
||
| 518 | * @return json|false Json with data or error, or False when something went fully wrong |
||
| 519 | */ |
||
| 520 | public function broadcastMessage($message = '') |
||
| 526 | |||
| 527 | } |
||
| 528 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.