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 |
||
| 33 | class Client implements ResourceOwner, ContainsRecordedMessages, DomainObject |
||
|
|
|||
| 34 | { |
||
| 35 | use PrivateMessageRecorderCapabilities; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var bool |
||
| 39 | */ |
||
| 40 | private $deleted = false; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @var UserAccountId|null |
||
| 44 | */ |
||
| 45 | private $ownerId = null; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @var ClientId|null |
||
| 49 | */ |
||
| 50 | private $clientId = null; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @var DataBag |
||
| 54 | */ |
||
| 55 | protected $parameters; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * ClientCredentials constructor. |
||
| 59 | */ |
||
| 60 | private function __construct() |
||
| 64 | |||
| 65 | /** |
||
| 66 | * {@inheritdoc} |
||
| 67 | */ |
||
| 68 | public static function getSchema(): string |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @return Client |
||
| 75 | */ |
||
| 76 | public static function createEmpty(): self |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @param ClientId $clientId |
||
| 83 | * @param DataBag $parameters |
||
| 84 | * @param UserAccountId|null $ownerId |
||
| 85 | * |
||
| 86 | * @return Client |
||
| 87 | */ |
||
| 88 | public function create(ClientId $clientId, DataBag $parameters, ? UserAccountId $ownerId): self |
||
| 100 | |||
| 101 | /** |
||
| 102 | * @return UserAccountId|null |
||
| 103 | */ |
||
| 104 | public function getOwnerId(): ? UserAccountId |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @param UserAccountId $ownerId |
||
| 111 | * |
||
| 112 | * @return Client |
||
| 113 | */ |
||
| 114 | public function withOwnerId(UserAccountId $ownerId): self |
||
| 127 | |||
| 128 | /** |
||
| 129 | * @param DataBag $parameters |
||
| 130 | * |
||
| 131 | * @return Client |
||
| 132 | */ |
||
| 133 | public function withParameters(DataBag $parameters): self |
||
| 142 | |||
| 143 | /** |
||
| 144 | * @return Client |
||
| 145 | */ |
||
| 146 | public function markAsDeleted(): self |
||
| 155 | |||
| 156 | /** |
||
| 157 | * @return bool |
||
| 158 | */ |
||
| 159 | public function isDeleted(): bool |
||
| 163 | |||
| 164 | /** |
||
| 165 | * @param string $grant_type |
||
| 166 | * |
||
| 167 | * @return bool |
||
| 168 | */ |
||
| 169 | public function isGrantTypeAllowed(string $grant_type): bool |
||
| 178 | |||
| 179 | /** |
||
| 180 | * @param string $response_type |
||
| 181 | * |
||
| 182 | * @return bool |
||
| 183 | */ |
||
| 184 | public function isResponseTypeAllowed(string $response_type): bool |
||
| 193 | |||
| 194 | /** |
||
| 195 | * @param string $token_type |
||
| 196 | * |
||
| 197 | * @return bool |
||
| 198 | */ |
||
| 199 | public function isTokenTypeAllowed(string $token_type): bool |
||
| 211 | |||
| 212 | /** |
||
| 213 | * @return bool |
||
| 214 | */ |
||
| 215 | public function isPublic(): bool |
||
| 219 | |||
| 220 | /** |
||
| 221 | * @return string |
||
| 222 | */ |
||
| 223 | public function getTokenEndpointAuthenticationMethod(): string |
||
| 231 | |||
| 232 | /** |
||
| 233 | * @return int |
||
| 234 | */ |
||
| 235 | public function getClientCredentialsExpiresAt(): int |
||
| 243 | |||
| 244 | /** |
||
| 245 | * @return bool |
||
| 246 | */ |
||
| 247 | public function areClientCredentialsExpired(): bool |
||
| 255 | |||
| 256 | /** |
||
| 257 | * {@inheritdoc} |
||
| 258 | */ |
||
| 259 | public function getPublicId(): ResourceOwnerId |
||
| 267 | |||
| 268 | /** |
||
| 269 | * {@inheritdoc} |
||
| 270 | */ |
||
| 271 | public function has(string $key): bool |
||
| 275 | |||
| 276 | /** |
||
| 277 | * {@inheritdoc} |
||
| 278 | */ |
||
| 279 | public function get(string $key) |
||
| 287 | |||
| 288 | /** |
||
| 289 | * @return array |
||
| 290 | */ |
||
| 291 | public function all(): array |
||
| 298 | |||
| 299 | /** |
||
| 300 | * {@inheritdoc} |
||
| 301 | */ |
||
| 302 | public function jsonSerialize() |
||
| 315 | |||
| 316 | /** |
||
| 317 | * {@inheritdoc} |
||
| 318 | */ |
||
| 319 | public static function createFromJson(\stdClass $json): DomainObject |
||
| 334 | |||
| 335 | /** |
||
| 336 | * @param Event $event |
||
| 337 | * |
||
| 338 | * @return Client |
||
| 339 | */ |
||
| 340 | public function apply(Event $event): self |
||
| 353 | |||
| 354 | /** |
||
| 355 | * @return array |
||
| 356 | */ |
||
| 357 | private function getEventMap(): array |
||
| 366 | |||
| 367 | /** |
||
| 368 | * @param ClientEvent\ClientCreatedEvent $event |
||
| 369 | * |
||
| 370 | * @return Client |
||
| 371 | */ |
||
| 372 | protected function applyClientCreatedEvent(ClientEvent\ClientCreatedEvent $event): self |
||
| 381 | |||
| 382 | /** |
||
| 383 | * @param ClientEvent\ClientOwnerChangedEvent $event |
||
| 384 | * |
||
| 385 | * @return Client |
||
| 386 | */ |
||
| 387 | protected function applyClientOwnerChangedEvent(ClientEvent\ClientOwnerChangedEvent $event): self |
||
| 394 | |||
| 395 | /** |
||
| 396 | * @param ClientEvent\ClientDeletedEvent $event |
||
| 397 | * |
||
| 398 | * @return Client |
||
| 399 | */ |
||
| 400 | protected function applyClientDeletedEvent(ClientEvent\ClientDeletedEvent $event): self |
||
| 407 | |||
| 408 | /** |
||
| 409 | * @param ClientEvent\ClientParametersUpdatedEvent $event |
||
| 410 | * |
||
| 411 | * @return Client |
||
| 412 | */ |
||
| 413 | protected function applyClientParametersUpdatedEvent(ClientEvent\ClientParametersUpdatedEvent $event): self |
||
| 420 | } |
||
| 421 |