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 | * @return bool |
||
196 | */ |
||
197 | public function isPublic(): bool |
||
201 | |||
202 | /** |
||
203 | * @return string |
||
204 | */ |
||
205 | public function getTokenEndpointAuthenticationMethod(): string |
||
213 | |||
214 | /** |
||
215 | * @return int |
||
216 | */ |
||
217 | public function getClientCredentialsExpiresAt(): int |
||
225 | |||
226 | /** |
||
227 | * @return bool |
||
228 | */ |
||
229 | public function areClientCredentialsExpired(): bool |
||
237 | |||
238 | /** |
||
239 | * {@inheritdoc} |
||
240 | */ |
||
241 | public function getPublicId(): ResourceOwnerId |
||
249 | |||
250 | /** |
||
251 | * {@inheritdoc} |
||
252 | */ |
||
253 | public function has(string $key): bool |
||
257 | |||
258 | /** |
||
259 | * {@inheritdoc} |
||
260 | */ |
||
261 | public function get(string $key) |
||
269 | |||
270 | /** |
||
271 | * @return array |
||
272 | */ |
||
273 | public function all(): array |
||
280 | |||
281 | /** |
||
282 | * {@inheritdoc} |
||
283 | */ |
||
284 | public function jsonSerialize() |
||
297 | |||
298 | /** |
||
299 | * {@inheritdoc} |
||
300 | */ |
||
301 | public static function createFromJson(\stdClass $json): DomainObject |
||
316 | |||
317 | /** |
||
318 | * @param Event $event |
||
319 | * |
||
320 | * @return Client |
||
321 | */ |
||
322 | public function apply(Event $event): self |
||
335 | |||
336 | /** |
||
337 | * @return array |
||
338 | */ |
||
339 | private function getEventMap(): array |
||
348 | |||
349 | /** |
||
350 | * @param ClientEvent\ClientCreatedEvent $event |
||
351 | * |
||
352 | * @return Client |
||
353 | */ |
||
354 | protected function applyClientCreatedEvent(ClientEvent\ClientCreatedEvent $event): self |
||
363 | |||
364 | /** |
||
365 | * @param ClientEvent\ClientOwnerChangedEvent $event |
||
366 | * |
||
367 | * @return Client |
||
368 | */ |
||
369 | protected function applyClientOwnerChangedEvent(ClientEvent\ClientOwnerChangedEvent $event): self |
||
376 | |||
377 | /** |
||
378 | * @param ClientEvent\ClientDeletedEvent $event |
||
379 | * |
||
380 | * @return Client |
||
381 | */ |
||
382 | protected function applyClientDeletedEvent(ClientEvent\ClientDeletedEvent $event): self |
||
389 | |||
390 | /** |
||
391 | * @param ClientEvent\ClientParametersUpdatedEvent $event |
||
392 | * |
||
393 | * @return Client |
||
394 | */ |
||
395 | protected function applyClientParametersUpdatedEvent(ClientEvent\ClientParametersUpdatedEvent $event): self |
||
402 | } |
||
403 |