Complex classes like UserModel 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 UserModel, and based on these observations, apply Extract Interface, too.
| 1 | <?php | ||
| 22 | class UserModel extends AbstractModel | ||
| 23 | {
 | ||
| 24 | /** | ||
| 25 | * @var string | ||
| 26 | */ | ||
| 27 | public static $endpoint = '/users'; | ||
| 28 | |||
| 29 | /** | ||
| 30 | * @param array $requestOptions | ||
| 31 | * @return ResponseInterface | ||
| 32 | */ | ||
| 33 | public function loginToUserAccount(array $requestOptions) | ||
| 37 | |||
| 38 | /** | ||
| 39 | * @return ResponseInterface | ||
| 40 | */ | ||
| 41 | public function logoutOfUserAccount() | ||
| 45 | |||
| 46 | /** | ||
| 47 | * @return ResponseInterface | ||
| 48 | */ | ||
| 49 | public function getAuthenticatedUser() | ||
| 53 | |||
| 54 | /** | ||
| 55 | * @param array $requestOptions | ||
| 56 | * @return ResponseInterface | ||
| 57 | */ | ||
| 58 | public function createUser(array $requestOptions) | ||
| 62 | |||
| 63 | /** | ||
| 64 | * @param array $requestOptions | ||
| 65 | * @return ResponseInterface | ||
| 66 | */ | ||
| 67 | public function getUsers(array $requestOptions) | ||
| 71 | |||
| 72 | /** | ||
| 73 | * @param array $requestOptions | ||
| 74 | * @return ResponseInterface | ||
| 75 | */ | ||
| 76 | public function getUsersByIds(array $requestOptions) | ||
| 80 | |||
| 81 | /** | ||
| 82 | * @param array $requestOptions | ||
| 83 | * @return ResponseInterface | ||
| 84 | */ | ||
| 85 | public function getUsersByGroupChannelsIds(array $requestOptions = []) | ||
| 89 | |||
| 90 | /** | ||
| 91 | * @param array $requestOptions | ||
| 92 | * @return ResponseInterface | ||
| 93 | */ | ||
| 94 | public function searchUsers(array $requestOptions) | ||
| 98 | |||
| 99 | /** | ||
| 100 | * @param array $requestOptions | ||
| 101 | * @return ResponseInterface | ||
| 102 | */ | ||
| 103 | public function autocompleteUsers(array $requestOptions) | ||
| 107 | |||
| 108 | /** | ||
| 109 | * @param $userId | ||
| 110 | * @return ResponseInterface | ||
| 111 | */ | ||
| 112 | public function getUser($userId) | ||
| 116 | |||
| 117 | /** | ||
| 118 | * @param $userId | ||
| 119 | * @param array $requestOptions | ||
| 120 | * @return ResponseInterface | ||
| 121 | */ | ||
| 122 | public function updateUser($userId, array $requestOptions) | ||
| 126 | |||
| 127 | /** | ||
| 128 | * @param $userId | ||
| 129 | * @return ResponseInterface | ||
| 130 | */ | ||
| 131 | public function deactivateUserAccount($userId) | ||
| 135 | |||
| 136 | /** | ||
| 137 | * @param $userId | ||
| 138 | * @param array $requestOptions | ||
| 139 | * @return ResponseInterface | ||
| 140 | */ | ||
| 141 | public function patchUser($userId, array $requestOptions) | ||
| 145 | |||
| 146 | /** | ||
| 147 | * @param $userId | ||
| 148 | * @param array $requestOptions | ||
| 149 | * @return ResponseInterface | ||
| 150 | */ | ||
| 151 | public function updateUserRoles($userId, array $requestOptions) | ||
| 155 | |||
| 156 | /** | ||
| 157 | * @param $userId | ||
| 158 | * @param array $requestOptions | ||
| 159 | * @return ResponseInterface | ||
| 160 | */ | ||
| 161 | public function updateUserActive($userId, array $requestOptions) | ||
| 165 | |||
| 166 | /** | ||
| 167 | * @param $userId | ||
| 168 | * @return ResponseInterface | ||
| 169 | */ | ||
| 170 | public function getUserProfileImage($userId) | ||
| 174 | |||
| 175 | /** | ||
| 176 | * @param $userId | ||
| 177 | * @param array $requestOptions | ||
| 178 | * @return ResponseInterface | ||
| 179 | */ | ||
| 180 | public function setUserProfileImage($userId, array $requestOptions) | ||
| 186 | |||
| 187 | /** | ||
| 188 | * @param $userId | ||
| 189 | * @return ResponseInterface | ||
| 190 | */ | ||
| 191 | public function deleteUserProfileImage($userId) | ||
| 195 | |||
| 196 | /** | ||
| 197 | * @param $userId | ||
| 198 | * @return ResponseInterface | ||
| 199 | */ | ||
| 200 | public function returnUserDefaultProfileImage($userId) | ||
| 204 | |||
| 205 | /** | ||
| 206 | * @param $username | ||
| 207 | * @return ResponseInterface | ||
| 208 | */ | ||
| 209 | public function getUserByUsername($username) | ||
| 213 | |||
| 214 | /** | ||
| 215 | * @param $requestOptions | ||
| 216 | * @return ResponseInterface | ||
| 217 | */ | ||
| 218 | public function getUsersByUsernames(array $requestOptions) | ||
| 222 | |||
| 223 | /** | ||
| 224 | * @param array $requestOptions | ||
| 225 | * @return ResponseInterface | ||
| 226 | */ | ||
| 227 | public function resetPassword(array $requestOptions) | ||
| 231 | |||
| 232 | /** | ||
| 233 | * @param $userId | ||
| 234 | * @param array $requestOptions | ||
| 235 | * @return ResponseInterface | ||
| 236 | */ | ||
| 237 | public function updateUserMfa($userId, array $requestOptions) | ||
| 241 | |||
| 242 | /** | ||
| 243 | * @param $userId | ||
| 244 | * @param array $requestOptions | ||
| 245 | * @return ResponseInterface | ||
| 246 | */ | ||
| 247 | public function generateMfaSecret($userId, array $requestOptions) | ||
| 251 | |||
| 252 | /** | ||
| 253 | * @param array $requestOptions | ||
| 254 | * @return ResponseInterface | ||
| 255 | */ | ||
| 256 | public function checkMfa(array $requestOptions) | ||
| 260 | |||
| 261 | /** | ||
| 262 | * @param $userId | ||
| 263 | * @param array $requestOptions | ||
| 264 | * @return ResponseInterface | ||
| 265 | */ | ||
| 266 | public function updateUserPassword($userId, array $requestOptions) | ||
| 270 | |||
| 271 | /** | ||
| 272 | * @param array $requestOptions | ||
| 273 | * @return ResponseInterface | ||
| 274 | */ | ||
| 275 | public function sendPasswordResetEmail(array $requestOptions) | ||
| 279 | |||
| 280 | /** | ||
| 281 | * @param $email | ||
| 282 | * @return ResponseInterface | ||
| 283 | */ | ||
| 284 | public function getUserByEmail($email) | ||
| 288 | |||
| 289 | /** | ||
| 290 | * @param $userId | ||
| 291 | * @return ResponseInterface | ||
| 292 | */ | ||
| 293 | public function getUserSessions($userId) | ||
| 297 | |||
| 298 | /** | ||
| 299 | * @param $userId | ||
| 300 | * @param array $requestOptions | ||
| 301 | * @return ResponseInterface | ||
| 302 | */ | ||
| 303 | public function revokeUserSession($userId, array $requestOptions) | ||
| 307 | |||
| 308 | /** | ||
| 309 | * @param $userId | ||
| 310 | * @return ResponseInterface | ||
| 311 | */ | ||
| 312 | public function revokeAllUserSessions($userId) | ||
| 316 | |||
| 317 | /** | ||
| 318 | * @param array $requestOptions | ||
| 319 | * @return ResponseInterface | ||
| 320 | */ | ||
| 321 | public function attachMobileDevice(array $requestOptions) | ||
| 325 | |||
| 326 | /** | ||
| 327 | * @param $userId | ||
| 328 | * @return ResponseInterface | ||
| 329 | */ | ||
| 330 | public function getUserAudits($userId) | ||
| 334 | |||
| 335 | /** | ||
| 336 | * @param array $requestOptions | ||
| 337 | * @return ResponseInterface | ||
| 338 | */ | ||
| 339 | public function verifyUserEmail(array $requestOptions) | ||
| 343 | |||
| 344 | /** | ||
| 345 | * @param array $requestOptions | ||
| 346 | * @return ResponseInterface | ||
| 347 | */ | ||
| 348 | public function sendVerificationEmail(array $requestOptions) | ||
| 352 | |||
| 353 | /** | ||
| 354 | * @param array $requestOptions | ||
| 355 | * @return ResponseInterface | ||
| 356 | */ | ||
| 357 | public function switchLoginMethod(array $requestOptions) | ||
| 361 | |||
| 362 | /** | ||
| 363 | * @param $userId | ||
| 364 | * @param array $requestOptions | ||
| 365 | * @return ResponseInterface | ||
| 366 | */ | ||
| 367 | public function createToken($userId, array $requestOptions) | ||
| 371 | |||
| 372 | /** | ||
| 373 | * @param $userId | ||
| 374 | * @param array $requestOptions | ||
| 375 | * @return ResponseInterface | ||
| 376 | */ | ||
| 377 | public function getTokens($userId, array $requestOptions) | ||
| 381 | |||
| 382 | /** | ||
| 383 | * @param $tokenId | ||
| 384 | * @return ResponseInterface | ||
| 385 | */ | ||
| 386 | public function getToken($tokenId) | ||
| 390 | |||
| 391 | /** | ||
| 392 | * @param array $requestOptions | ||
| 393 | * @return ResponseInterface | ||
| 394 | */ | ||
| 395 | public function revokeToken(array $requestOptions) | ||
| 399 | |||
| 400 | /** | ||
| 401 | * @param array $requestOptions | ||
| 402 | * @return ResponseInterface | ||
| 403 | */ | ||
| 404 | public function disablePersonalAccessToken(array $requestOptions) | ||
| 408 | |||
| 409 | /** | ||
| 410 | * @param array $requestOptions | ||
| 411 | * @return ResponseInterface | ||
| 412 | */ | ||
| 413 | public function enablePersonalAccessToken(array $requestOptions) | ||
| 417 | |||
| 418 | /** | ||
| 419 | * @param array $requestOptions | ||
| 420 | * @return ResponseInterface | ||
| 421 | */ | ||
| 422 | public function searchTokens(array $requestOptions) | ||
| 426 | |||
| 427 | /** | ||
| 428 | * @param $userId | ||
| 429 | * @return ResponseInterface | ||
| 430 | */ | ||
| 431 | public function getUserStatus($userId) | ||
| 435 | |||
| 436 | /** | ||
| 437 | * @param $userId | ||
| 438 | * @param array $requestOptions | ||
| 439 | * @return ResponseInterface | ||
| 440 | */ | ||
| 441 | public function updateUserStatus($userId, array $requestOptions) | ||
| 445 | |||
| 446 | /** | ||
| 447 | * @param $userId | ||
| 448 | * @param array $requestOptions | ||
|  | |||
| 449 | * @return ResponseInterface | ||
| 450 | */ | ||
| 451 | public function removeUserCustomStatus($userId) | ||
| 455 | |||
| 456 | /** | ||
| 457 | * @param $userId | ||
| 458 | * @param array $requestOptions | ||
| 459 | * @return ResponseInterface | ||
| 460 | */ | ||
| 461 | public function updateUserCustomStatus($userId, array $requestOptions) | ||
| 465 | |||
| 466 | /** | ||
| 467 | * @param $userId | ||
| 468 | * @param array $requestOptions | ||
| 469 | * @return ResponseInterface | ||
| 470 | */ | ||
| 471 | public function updateUserAuthenticationMethod($userId, array $requestOptions) | ||
| 475 | |||
| 476 | /** | ||
| 477 | * @return ResponseInterface | ||
| 478 | */ | ||
| 479 | public function getTotalCountOfUsersInTheSystem() | ||
| 483 | |||
| 484 | /** | ||
| 485 | * @param $userId | ||
| 486 | * @return ResponseInterface | ||
| 487 | */ | ||
| 488 | public function promoteGuestToUser($userId) | ||
| 492 | |||
| 493 | /** | ||
| 494 | * @param $userId | ||
| 495 | * @return ResponseInterface | ||
| 496 | */ | ||
| 497 | public function demoteUserToGuest($userId) | ||
| 501 | |||
| 502 | /** | ||
| 503 | * @return ResponseInterface | ||
| 504 | */ | ||
| 505 | public function getUserIdsOfKnownUsers() | ||
| 509 | |||
| 510 | /** | ||
| 511 | * @param $userId | ||
| 512 | * @return ResponseInterface | ||
| 513 | */ | ||
| 514 | public function getGroupsForUserId($userId) | ||
| 518 | |||
| 519 | /** | ||
| 520 | * @param $userId | ||
| 521 | * @return ResponseInterface | ||
| 522 | */ | ||
| 523 | public function convertUserIntoBot($userId) | ||
| 527 | |||
| 528 | /** | ||
| 529 | * @param array $requestOptions | ||
| 530 | * @return ResponseInterface | ||
| 531 | */ | ||
| 532 | public function getTotalCountOfUsersMatchingSpecifiedFilters(array $requestOptions) | ||
| 536 | |||
| 537 | /** | ||
| 538 | * @param $userId | ||
| 539 | * @return ResponseInterface | ||
| 540 | */ | ||
| 541 | public function verifyUserEmailById($userId) | ||
| 545 | |||
| 546 | /** | ||
| 547 | * @param $userId | ||
| 548 | * @return ResponseInterface | ||
| 549 | */ | ||
| 550 | public function publishUserTypingWebsocketEvent($userId) | ||
| 554 | } | ||
| 555 | 
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.