Complex classes like AuthorizationRequest 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 AuthorizationRequest, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
25 | class AuthorizationRequest |
||
26 | { |
||
27 | /** |
||
28 | * @var bool |
||
29 | */ |
||
30 | private $authorized; |
||
31 | |||
32 | /** |
||
33 | * @var Client |
||
34 | */ |
||
35 | private $client; |
||
36 | |||
37 | /** |
||
38 | * @var User|null |
||
39 | */ |
||
40 | private $user = null; |
||
41 | |||
42 | /** |
||
43 | * @var UserAccount|null |
||
44 | */ |
||
45 | private $userAccount = null; |
||
46 | |||
47 | /** |
||
48 | * @var DataBag |
||
49 | */ |
||
50 | private $metadata; |
||
51 | |||
52 | /** |
||
53 | * @var TokenType|null |
||
54 | */ |
||
55 | private $tokenType = null; |
||
56 | |||
57 | /** |
||
58 | * @var ResponseType] |
||
59 | */ |
||
60 | private $responseType = null; |
||
61 | |||
62 | /** |
||
63 | * @var ResponseMode|null |
||
64 | */ |
||
65 | private $responseMode = null; |
||
66 | |||
67 | /** |
||
68 | * @var array |
||
69 | */ |
||
70 | private $queryParameters = []; |
||
71 | |||
72 | /** |
||
73 | * @var string|null |
||
74 | */ |
||
75 | private $redirectUri = null; |
||
76 | |||
77 | /** |
||
78 | * @var array |
||
79 | */ |
||
80 | private $consentScreenOptions = []; |
||
81 | |||
82 | /** |
||
83 | * @var array |
||
84 | */ |
||
85 | private $responseParameters = []; |
||
86 | |||
87 | /** |
||
88 | * @var array |
||
89 | */ |
||
90 | private $responseHeaders = []; |
||
91 | |||
92 | /** |
||
93 | * @var null|ResourceServer |
||
94 | */ |
||
95 | private $resourceServer = null; |
||
96 | |||
97 | public function __construct(Client $client, array $queryParameters) |
||
103 | |||
104 | public function getQueryParams(): array |
||
108 | |||
109 | public function hasQueryParam(string $param): bool |
||
113 | |||
114 | public function getQueryParam(string $param) |
||
122 | |||
123 | public function getClient(): Client |
||
127 | |||
128 | public function setTokenType(TokenType $tokenType): void |
||
132 | |||
133 | public function getTokenType(): ?TokenType |
||
137 | |||
138 | public function setResponseType(ResponseType $responseType): void |
||
142 | |||
143 | public function getResponseType(): ResponseType |
||
147 | |||
148 | public function setResponseMode(ResponseMode $responseMode): void |
||
152 | |||
153 | public function getResponseMode(): ?ResponseMode |
||
157 | |||
158 | public function setRedirectUri(string $redirectUri): void |
||
162 | |||
163 | public function getRedirectUri(): ?string |
||
167 | |||
168 | public function setUser(User $user): void |
||
172 | |||
173 | public function getUser(): ?User |
||
177 | |||
178 | public function setUserAccount(UserAccount $userAccount): void |
||
182 | |||
183 | public function getUserAccount(): ?UserAccount |
||
187 | |||
188 | public function setResponseParameter(string $responseParameter, $value): void |
||
192 | |||
193 | public function getResponseParameters(): array |
||
197 | |||
198 | public function getResponseParameter(string $param) |
||
206 | |||
207 | public function hasResponseParameter(string $param): bool |
||
211 | |||
212 | public function setResponseHeader(string $responseHeader, $value): void |
||
216 | |||
217 | public function getResponseHeaders(): array |
||
221 | |||
222 | /** |
||
223 | * @return string[] |
||
224 | */ |
||
225 | public function getPrompt(): array |
||
233 | |||
234 | public function hasUiLocales(): bool |
||
238 | |||
239 | /** |
||
240 | * @return string[] |
||
241 | */ |
||
242 | public function getUiLocales(): array |
||
246 | |||
247 | public function hasPrompt(string $prompt): bool |
||
251 | |||
252 | public function isAuthorized(): bool |
||
256 | |||
257 | public function allow(): void |
||
261 | |||
262 | public function deny(): void |
||
266 | |||
267 | public function getResourceServer(): ?ResourceServer |
||
271 | |||
272 | public function setResourceServer(ResourceServer $resourceServer): void |
||
276 | |||
277 | public function setConsentScreenOption(string $option, $value): void |
||
281 | |||
282 | public function hasScope(): bool |
||
286 | |||
287 | public function getScope(): string |
||
291 | |||
292 | public function getMetadata(): DataBag |
||
296 | } |
||
297 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.