Complex classes like Client 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 Client, and based on these observations, apply Extract Interface, too.
| 1 | <?php declare(strict_types=1); |
||
| 31 | abstract class Client extends DatabaseItem implements ClientInterface |
||
| 32 | { |
||
| 33 | /** Field name */ |
||
| 34 | const FIELD_ID = 'id_client'; |
||
| 35 | |||
| 36 | /** Field name */ |
||
| 37 | const FIELD_NAME = 'name'; |
||
| 38 | |||
| 39 | /** Field name */ |
||
| 40 | const FIELD_DESCRIPTION = 'description'; |
||
| 41 | |||
| 42 | /** Field name */ |
||
| 43 | const FIELD_CREDENTIALS = 'credentials'; |
||
| 44 | |||
| 45 | /** Field name */ |
||
| 46 | const FIELD_REDIRECT_URIS = 'redirect_uris'; |
||
| 47 | |||
| 48 | /** Field name */ |
||
| 49 | const FIELD_SCOPES = 'scopes'; |
||
| 50 | |||
| 51 | /** Field name */ |
||
| 52 | const FIELD_IS_CONFIDENTIAL = 'is_confidential'; |
||
| 53 | |||
| 54 | /** Field name */ |
||
| 55 | const FIELD_IS_USE_DEFAULT_SCOPE = 'is_use_default_scope'; |
||
| 56 | |||
| 57 | /** Field name */ |
||
| 58 | const FIELD_IS_SCOPE_EXCESS_ALLOWED = 'is_scope_excess_allowed'; |
||
| 59 | |||
| 60 | /** Field name */ |
||
| 61 | const FIELD_IS_CODE_GRANT_ENABLED = 'is_code_grant_enabled'; |
||
| 62 | |||
| 63 | /** Field name */ |
||
| 64 | const FIELD_IS_IMPLICIT_GRANT_ENABLED = 'is_implicit_grant_enabled'; |
||
| 65 | |||
| 66 | /** Field name */ |
||
| 67 | const FIELD_IS_PASSWORD_GRANT_ENABLED = 'is_password_grant_enabled'; |
||
| 68 | |||
| 69 | /** Field name */ |
||
| 70 | const FIELD_IS_CLIENT_GRANT_ENABLED = 'is_client_grant_enabled'; |
||
| 71 | |||
| 72 | /** Field name */ |
||
| 73 | const FIELD_IS_REFRESH_GRANT_ENABLED = 'is_refresh_grant_enabled'; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * @var string |
||
| 77 | */ |
||
| 78 | private $identifierField = ''; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @var string|null |
||
| 82 | */ |
||
| 83 | private $nameField = null; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @var string|null |
||
| 87 | */ |
||
| 88 | private $descriptionField = null; |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @var string|null |
||
| 92 | */ |
||
| 93 | private $credentialsField = null; |
||
| 94 | |||
| 95 | /** |
||
| 96 | * @var string[] |
||
| 97 | */ |
||
| 98 | private $redirectUriStrings; |
||
| 99 | |||
| 100 | /** |
||
| 101 | * @var string[] |
||
| 102 | */ |
||
| 103 | private $scopeIdentifiers; |
||
| 104 | |||
| 105 | /** |
||
| 106 | * @var bool |
||
| 107 | */ |
||
| 108 | private $isConfidentialField = false; |
||
| 109 | |||
| 110 | /** |
||
| 111 | * @var bool |
||
| 112 | */ |
||
| 113 | private $isUseDefaultScopeField = false; |
||
| 114 | |||
| 115 | /** |
||
| 116 | * @var bool |
||
| 117 | */ |
||
| 118 | private $isScopeExcessAllowedField = false; |
||
| 119 | |||
| 120 | /** |
||
| 121 | * @var bool |
||
| 122 | */ |
||
| 123 | private $isCodeAuthEnabledField = false; |
||
| 124 | |||
| 125 | /** |
||
| 126 | * @var bool |
||
| 127 | */ |
||
| 128 | private $isImplicitAuthEnabledField = false; |
||
| 129 | |||
| 130 | /** |
||
| 131 | * @var bool |
||
| 132 | */ |
||
| 133 | private $isPasswordGrantEnabledField = false; |
||
| 134 | |||
| 135 | /** |
||
| 136 | * @var bool |
||
| 137 | */ |
||
| 138 | private $isClientGrantEnabledField = false; |
||
| 139 | |||
| 140 | /** |
||
| 141 | * @var bool |
||
| 142 | */ |
||
| 143 | private $isRefreshGrantEnabledField = false; |
||
| 144 | |||
| 145 | /** |
||
| 146 | * Constructor. |
||
| 147 | * |
||
| 148 | * @SuppressWarnings(PHPMD.ElseExpression) |
||
| 149 | */ |
||
| 150 | 33 | public function __construct() |
|
| 172 | |||
| 173 | /** |
||
| 174 | * @inheritdoc |
||
| 175 | */ |
||
| 176 | 27 | public function getIdentifier(): string |
|
| 180 | |||
| 181 | /** |
||
| 182 | * @inheritdoc |
||
| 183 | */ |
||
| 184 | 26 | public function setIdentifier(string $identifier): ClientInterface |
|
| 190 | |||
| 191 | /** |
||
| 192 | * @inheritdoc |
||
| 193 | */ |
||
| 194 | 26 | public function getName(): ?string |
|
| 198 | |||
| 199 | /** |
||
| 200 | * @inheritdoc |
||
| 201 | */ |
||
| 202 | 26 | public function setName(string $name): ClientInterface |
|
| 208 | |||
| 209 | /** |
||
| 210 | * @inheritdoc |
||
| 211 | */ |
||
| 212 | 26 | public function getDescription(): ?string |
|
| 216 | |||
| 217 | /** |
||
| 218 | * @inheritdoc |
||
| 219 | */ |
||
| 220 | 17 | public function setDescription(string $description = null): ClientInterface |
|
| 226 | |||
| 227 | /** |
||
| 228 | * @inheritdoc |
||
| 229 | */ |
||
| 230 | 27 | public function getCredentials(): ?string |
|
| 234 | |||
| 235 | /** |
||
| 236 | * @inheritdoc |
||
| 237 | */ |
||
| 238 | 19 | public function setCredentials(string $credentials = null): ClientInterface |
|
| 244 | |||
| 245 | /** |
||
| 246 | * @inheritdoc |
||
| 247 | */ |
||
| 248 | 7 | public function hasCredentials(): bool |
|
| 252 | |||
| 253 | /** |
||
| 254 | * @inheritdoc |
||
| 255 | */ |
||
| 256 | 8 | public function getRedirectUriStrings(): array |
|
| 260 | |||
| 261 | /** |
||
| 262 | * @inheritdoc |
||
| 263 | */ |
||
| 264 | 33 | public function setRedirectUriStrings(array $redirectUriStrings): ClientInterface |
|
| 270 | |||
| 271 | /** |
||
| 272 | * @inheritdoc |
||
| 273 | */ |
||
| 274 | 28 | public function getScopeIdentifiers(): array |
|
| 278 | |||
| 279 | /** |
||
| 280 | * @param string[] $scopeIdentifiers |
||
| 281 | * |
||
| 282 | * @return ClientInterface |
||
| 283 | */ |
||
| 284 | 33 | public function setScopeIdentifiers(array $scopeIdentifiers): ClientInterface |
|
| 290 | |||
| 291 | /** |
||
| 292 | * @inheritdoc |
||
| 293 | */ |
||
| 294 | 28 | public function isConfidential(): bool |
|
| 298 | |||
| 299 | /** |
||
| 300 | * @inheritdoc |
||
| 301 | */ |
||
| 302 | 1 | public function isPublic(): bool |
|
| 306 | |||
| 307 | /** |
||
| 308 | * @inheritdoc |
||
| 309 | */ |
||
| 310 | 3 | public function setConfidential(): ClientInterface |
|
| 316 | |||
| 317 | /** |
||
| 318 | * @inheritdoc |
||
| 319 | */ |
||
| 320 | 16 | public function setPublic(): ClientInterface |
|
| 326 | |||
| 327 | /** |
||
| 328 | * @inheritdoc |
||
| 329 | */ |
||
| 330 | 26 | public function isUseDefaultScopesOnEmptyRequest(): bool |
|
| 334 | |||
| 335 | /** |
||
| 336 | * @inheritdoc |
||
| 337 | */ |
||
| 338 | 16 | public function useDefaultScopesOnEmptyRequest(): ClientInterface |
|
| 344 | |||
| 345 | /** |
||
| 346 | * @inheritdoc |
||
| 347 | */ |
||
| 348 | 4 | public function doNotUseDefaultScopesOnEmptyRequest(): ClientInterface |
|
| 354 | |||
| 355 | /** |
||
| 356 | * @inheritdoc |
||
| 357 | */ |
||
| 358 | 27 | public function isScopeExcessAllowed(): bool |
|
| 362 | |||
| 363 | /** |
||
| 364 | * @inheritdoc |
||
| 365 | */ |
||
| 366 | 1 | public function enableScopeExcess(): ClientInterface |
|
| 372 | |||
| 373 | /** |
||
| 374 | * @inheritdoc |
||
| 375 | */ |
||
| 376 | 17 | public function disableScopeExcess(): ClientInterface |
|
| 382 | |||
| 383 | /** |
||
| 384 | * @inheritdoc |
||
| 385 | */ |
||
| 386 | 26 | public function isCodeGrantEnabled(): bool |
|
| 390 | |||
| 391 | /** |
||
| 392 | * @inheritdoc |
||
| 393 | */ |
||
| 394 | 16 | public function enableCodeGrant(): ClientInterface |
|
| 400 | |||
| 401 | /** |
||
| 402 | * @inheritdoc |
||
| 403 | */ |
||
| 404 | 4 | public function disableCodeGrant(): ClientInterface |
|
| 410 | |||
| 411 | /** |
||
| 412 | * @inheritdoc |
||
| 413 | */ |
||
| 414 | 26 | public function isImplicitGrantEnabled(): bool |
|
| 418 | |||
| 419 | /** |
||
| 420 | * @inheritdoc |
||
| 421 | */ |
||
| 422 | 16 | public function enableImplicitGrant(): ClientInterface |
|
| 428 | |||
| 429 | /** |
||
| 430 | * @inheritdoc |
||
| 431 | */ |
||
| 432 | 4 | public function disableImplicitGrant(): ClientInterface |
|
| 438 | |||
| 439 | /** |
||
| 440 | * @inheritdoc |
||
| 441 | */ |
||
| 442 | 26 | public function isPasswordGrantEnabled(): bool |
|
| 446 | |||
| 447 | /** |
||
| 448 | * @inheritdoc |
||
| 449 | */ |
||
| 450 | 18 | public function enablePasswordGrant(): ClientInterface |
|
| 456 | |||
| 457 | /** |
||
| 458 | * @inheritdoc |
||
| 459 | */ |
||
| 460 | 3 | public function disablePasswordGrant(): ClientInterface |
|
| 466 | |||
| 467 | /** |
||
| 468 | * @inheritdoc |
||
| 469 | */ |
||
| 470 | 26 | public function isClientGrantEnabled(): bool |
|
| 474 | |||
| 475 | /** |
||
| 476 | * @inheritdoc |
||
| 477 | */ |
||
| 478 | 1 | public function enableClientGrant(): ClientInterface |
|
| 484 | |||
| 485 | /** |
||
| 486 | * @inheritdoc |
||
| 487 | */ |
||
| 488 | 17 | public function disableClientGrant(): ClientInterface |
|
| 494 | |||
| 495 | /** |
||
| 496 | * @inheritdoc |
||
| 497 | */ |
||
| 498 | 25 | public function isRefreshGrantEnabled(): bool |
|
| 502 | |||
| 503 | /** |
||
| 504 | * @inheritdoc |
||
| 505 | */ |
||
| 506 | 16 | public function enableRefreshGrant(): ClientInterface |
|
| 512 | |||
| 513 | /** |
||
| 514 | * @inheritdoc |
||
| 515 | */ |
||
| 516 | 4 | public function disableRefreshGrant(): ClientInterface |
|
| 522 | |||
| 523 | /** |
||
| 524 | * @inheritdoc |
||
| 525 | */ |
||
| 526 | 24 | public function setCreatedAt(DateTimeInterface $createdAt): ClientInterface |
|
| 533 | |||
| 534 | /** |
||
| 535 | * @inheritdoc |
||
| 536 | */ |
||
| 537 | 2 | public function setUpdatedAt(DateTimeInterface $createdAt): ClientInterface |
|
| 544 | |||
| 545 | /** |
||
| 546 | * @param string $value |
||
| 547 | * |
||
| 548 | * @return Client |
||
| 549 | */ |
||
| 550 | 17 | protected function parseIsConfidential(string $value): Client |
|
| 556 | |||
| 557 | /** |
||
| 558 | * @param string $value |
||
| 559 | * |
||
| 560 | * @return Client |
||
| 561 | */ |
||
| 562 | 17 | protected function parseIsUseDefaultScope(string $value): Client |
|
| 568 | |||
| 569 | /** |
||
| 570 | * @param string $value |
||
| 571 | * |
||
| 572 | * @return Client |
||
| 573 | */ |
||
| 574 | 17 | protected function parseIsScopeExcessAllowed(string $value): Client |
|
| 580 | |||
| 581 | /** |
||
| 582 | * @param string $value |
||
| 583 | * |
||
| 584 | * @return Client |
||
| 585 | */ |
||
| 586 | 17 | protected function parseIsCodeAuthEnabled(string $value): Client |
|
| 592 | |||
| 593 | /** |
||
| 594 | * @param string $value |
||
| 595 | * |
||
| 596 | * @return Client |
||
| 597 | */ |
||
| 598 | 17 | protected function parseIsImplicitAuthEnabled(string $value): Client |
|
| 604 | |||
| 605 | /** |
||
| 606 | * @param string $value |
||
| 607 | * |
||
| 608 | * @return Client |
||
| 609 | */ |
||
| 610 | 17 | protected function parseIsPasswordGrantEnabled(string $value): Client |
|
| 616 | |||
| 617 | /** |
||
| 618 | * @param string $value |
||
| 619 | * |
||
| 620 | * @return Client |
||
| 621 | */ |
||
| 622 | 17 | protected function parseIsClientGrantEnabled(string $value): Client |
|
| 628 | |||
| 629 | /** |
||
| 630 | * @param string $value |
||
| 631 | * |
||
| 632 | * @return Client |
||
| 633 | */ |
||
| 634 | 17 | protected function parseIsRefreshGrantEnabled(string $value): Client |
|
| 640 | } |
||
| 641 |