Complex classes like Authorization 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 Authorization, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
23 | class Authorization |
||
|
|||
24 | { |
||
25 | /** |
||
26 | * @var bool |
||
27 | */ |
||
28 | private $authorized; |
||
29 | |||
30 | /** |
||
31 | * @var Client |
||
32 | */ |
||
33 | private $client; |
||
34 | |||
35 | /** |
||
36 | * @var UserAccount|null |
||
37 | */ |
||
38 | private $userAccount = null; |
||
39 | |||
40 | /** |
||
41 | * @var DataBag |
||
42 | */ |
||
43 | private $metadata; |
||
44 | |||
45 | /** |
||
46 | * @var null|bool |
||
47 | */ |
||
48 | private $userAccountFullyAuthenticated = null; |
||
49 | |||
50 | /** |
||
51 | * @var array |
||
52 | */ |
||
53 | private $data = []; |
||
54 | |||
55 | /** |
||
56 | * @var TokenType|null |
||
57 | */ |
||
58 | private $tokenType = null; |
||
59 | |||
60 | /** |
||
61 | * @var ResponseType] |
||
62 | */ |
||
63 | private $responseType = null; |
||
64 | |||
65 | /** |
||
66 | * @var ResponseMode|null |
||
67 | */ |
||
68 | private $responseMode = null; |
||
69 | |||
70 | /** |
||
71 | * @var array |
||
72 | */ |
||
73 | private $queryParameters = []; |
||
74 | |||
75 | /** |
||
76 | * @var string|null |
||
77 | */ |
||
78 | private $redirectUri = null; |
||
79 | |||
80 | /** |
||
81 | * @var array |
||
82 | */ |
||
83 | private $consentScreenOptions = []; |
||
84 | |||
85 | /** |
||
86 | * @var array |
||
87 | */ |
||
88 | private $responseParameters = []; |
||
89 | |||
90 | /** |
||
91 | * @var array |
||
92 | */ |
||
93 | private $responseHeaders = []; |
||
94 | |||
95 | /** |
||
96 | * @var null|ResourceServer |
||
97 | */ |
||
98 | private $resourceServer = null; |
||
99 | |||
100 | /** |
||
101 | * Authorization constructor. |
||
102 | * |
||
103 | * @param Client $client |
||
104 | * @param array $queryParameters |
||
105 | */ |
||
106 | private function __construct(Client $client, array $queryParameters) |
||
112 | |||
113 | /** |
||
114 | * @param Client $client |
||
115 | * @param array $queryParameters |
||
116 | * |
||
117 | * @return Authorization |
||
118 | */ |
||
119 | public static function create(Client $client, array $queryParameters): self |
||
123 | |||
124 | /** |
||
125 | * @return array |
||
126 | */ |
||
127 | public function getQueryParams(): array |
||
131 | |||
132 | /** |
||
133 | * @param string $param |
||
134 | * |
||
135 | * @return bool |
||
136 | */ |
||
137 | public function hasQueryParam(string $param): bool |
||
141 | |||
142 | /** |
||
143 | * @param string $param |
||
144 | * |
||
145 | * @return mixed |
||
146 | */ |
||
147 | public function getQueryParam(string $param) |
||
155 | |||
156 | /** |
||
157 | * @return Client |
||
158 | */ |
||
159 | public function getClient(): Client |
||
163 | |||
164 | /** |
||
165 | * @param TokenType $tokenType |
||
166 | * |
||
167 | * @return Authorization |
||
168 | */ |
||
169 | public function withTokenType(TokenType $tokenType): self |
||
175 | |||
176 | /** |
||
177 | * @return null|TokenType |
||
178 | */ |
||
179 | public function getTokenType(): ? TokenType |
||
183 | |||
184 | /** |
||
185 | * @param ResponseType $responseType |
||
186 | * |
||
187 | * @return Authorization |
||
188 | */ |
||
189 | public function withResponseType(ResponseType $responseType): self |
||
195 | |||
196 | /** |
||
197 | * @return ResponseType |
||
198 | */ |
||
199 | public function getResponseType(): ResponseType |
||
203 | |||
204 | /** |
||
205 | * @param ResponseMode $responseMode |
||
206 | * |
||
207 | * @return Authorization |
||
208 | */ |
||
209 | public function withResponseMode(ResponseMode $responseMode): self |
||
215 | |||
216 | /** |
||
217 | * @return null|ResponseMode |
||
218 | */ |
||
219 | public function getResponseMode(): ? ResponseMode |
||
223 | |||
224 | /** |
||
225 | * @param string $redirectUri |
||
226 | * |
||
227 | * @return Authorization |
||
228 | */ |
||
229 | public function withRedirectUri(string $redirectUri): self |
||
236 | |||
237 | /** |
||
238 | * @return array|null |
||
239 | */ |
||
240 | public function getClaims(): ?array |
||
248 | |||
249 | /** |
||
250 | * @return null|string |
||
251 | */ |
||
252 | public function getRedirectUri(): ? string |
||
256 | |||
257 | /** |
||
258 | * @param UserAccount $userAccount |
||
259 | * @param bool $isFullyAuthenticated |
||
260 | * |
||
261 | * @return Authorization |
||
262 | */ |
||
263 | public function withUserAccount(UserAccount $userAccount, bool $isFullyAuthenticated): self |
||
270 | |||
271 | /** |
||
272 | * @return null|UserAccount |
||
273 | */ |
||
274 | public function getUserAccount(): ? UserAccount |
||
278 | |||
279 | /** |
||
280 | * @param string $responseParameter |
||
281 | * @param mixed $value |
||
282 | * |
||
283 | * @return Authorization |
||
284 | */ |
||
285 | public function withResponseParameter(string $responseParameter, $value): self |
||
291 | |||
292 | /** |
||
293 | * @return array |
||
294 | */ |
||
295 | public function getResponseParameters(): array |
||
299 | |||
300 | /** |
||
301 | * @param string $param |
||
302 | * |
||
303 | * @return mixed |
||
304 | */ |
||
305 | public function getResponseParameter(string $param) |
||
313 | |||
314 | /** |
||
315 | * @param string $param |
||
316 | * |
||
317 | * @return bool |
||
318 | */ |
||
319 | public function hasResponseParameter(string $param): bool |
||
323 | |||
324 | /** |
||
325 | * @param string $responseHeader |
||
326 | * @param mixed $value |
||
327 | * |
||
328 | * @return Authorization |
||
329 | */ |
||
330 | public function withResponseHeader(string $responseHeader, $value): self |
||
336 | |||
337 | /** |
||
338 | * @return array |
||
339 | */ |
||
340 | public function getResponseHeaders(): array |
||
344 | |||
345 | /** |
||
346 | * @return bool|null |
||
347 | */ |
||
348 | public function isUserAccountFullyAuthenticated(): ? bool |
||
352 | |||
353 | /** |
||
354 | * @return string[] |
||
355 | */ |
||
356 | public function getPrompt(): array |
||
364 | |||
365 | /** |
||
366 | * @return bool |
||
367 | */ |
||
368 | public function hasUiLocales(): bool |
||
372 | |||
373 | /** |
||
374 | * @return string[] |
||
375 | */ |
||
376 | public function getUiLocales(): array |
||
380 | |||
381 | /** |
||
382 | * @param string $prompt |
||
383 | * |
||
384 | * @return bool |
||
385 | */ |
||
386 | public function hasPrompt(string $prompt): bool |
||
390 | |||
391 | /** |
||
392 | * @return bool |
||
393 | */ |
||
394 | public function isAuthorized(): bool |
||
398 | |||
399 | /** |
||
400 | * @return Authorization |
||
401 | */ |
||
402 | public function allow(): self |
||
408 | |||
409 | /** |
||
410 | * @return Authorization |
||
411 | */ |
||
412 | public function deny(): self |
||
418 | |||
419 | /** |
||
420 | * @param string $key |
||
421 | * |
||
422 | * @return bool |
||
423 | */ |
||
424 | public function hasData(string $key): bool |
||
428 | |||
429 | /** |
||
430 | * @param string $key |
||
431 | * |
||
432 | * @return mixed |
||
433 | */ |
||
434 | public function getData(string $key) |
||
442 | |||
443 | /** |
||
444 | * @param string $key |
||
445 | * @param mixed $data |
||
446 | * |
||
447 | * @return Authorization |
||
448 | */ |
||
449 | public function withData(string $key, $data): self |
||
455 | |||
456 | /** |
||
457 | * @return null|ResourceServer |
||
458 | */ |
||
459 | public function getResourceServer(): ? ResourceServer |
||
463 | |||
464 | /** |
||
465 | * @param ResourceServer $resourceServer |
||
466 | * |
||
467 | * @return Authorization |
||
468 | */ |
||
469 | public function withResourceServer(ResourceServer $resourceServer): self |
||
475 | |||
476 | /** |
||
477 | * @param string $option |
||
478 | * @param mixed $value |
||
479 | * |
||
480 | * @return Authorization |
||
481 | */ |
||
482 | public function withConsentScreenOption(string $option, $value): self |
||
488 | |||
489 | /** |
||
490 | * @param string $option |
||
491 | * |
||
492 | * @return Authorization |
||
493 | */ |
||
494 | public function withoutConsentScreenOption(string $option): self |
||
504 | |||
505 | public function hasScope(): bool |
||
509 | |||
510 | /** |
||
511 | * @return string |
||
512 | */ |
||
513 | public function getScope(): string |
||
517 | |||
518 | public function getMetadata(): DataBag |
||
522 | } |
||
523 |