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 |
||
| 24 | class AuthorizationRequest |
||
| 25 | { |
||
| 26 | /** |
||
| 27 | * @var bool |
||
| 28 | */ |
||
| 29 | private $authorized; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var Client |
||
| 33 | */ |
||
| 34 | private $client; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var UserAccount|null |
||
| 38 | */ |
||
| 39 | private $userAccount = null; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var DataBag |
||
| 43 | */ |
||
| 44 | private $metadata; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @var null|bool |
||
| 48 | */ |
||
| 49 | private $userAccountFullyAuthenticated = null; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @var array |
||
| 53 | */ |
||
| 54 | private $data = []; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @var TokenType|null |
||
| 58 | */ |
||
| 59 | private $tokenType = null; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @var ResponseType] |
||
| 63 | */ |
||
| 64 | private $responseType = null; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @var ResponseMode|null |
||
| 68 | */ |
||
| 69 | private $responseMode = null; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @var array |
||
| 73 | */ |
||
| 74 | private $queryParameters = []; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @var string|null |
||
| 78 | */ |
||
| 79 | private $redirectUri = null; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @var array |
||
| 83 | */ |
||
| 84 | private $consentScreenOptions = []; |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @var array |
||
| 88 | */ |
||
| 89 | private $responseParameters = []; |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @var array |
||
| 93 | */ |
||
| 94 | private $responseHeaders = []; |
||
| 95 | |||
| 96 | /** |
||
| 97 | * @var null|ResourceServer |
||
| 98 | */ |
||
| 99 | private $resourceServer = null; |
||
| 100 | |||
| 101 | public function __construct(Client $client, array $queryParameters) |
||
| 107 | |||
| 108 | public function getQueryParams(): array |
||
| 112 | |||
| 113 | public function hasQueryParam(string $param): bool |
||
| 117 | |||
| 118 | public function getQueryParam(string $param) |
||
| 126 | |||
| 127 | public function getClient(): Client |
||
| 131 | |||
| 132 | public function setTokenType(TokenType $tokenType): void |
||
| 136 | |||
| 137 | public function getTokenType(): ?TokenType |
||
| 141 | |||
| 142 | public function setResponseType(ResponseType $responseType): void |
||
| 146 | |||
| 147 | public function getResponseType(): ResponseType |
||
| 151 | |||
| 152 | public function setResponseMode(ResponseMode $responseMode): void |
||
| 156 | |||
| 157 | public function getResponseMode(): ?ResponseMode |
||
| 161 | |||
| 162 | public function setRedirectUri(string $redirectUri): void |
||
| 167 | |||
| 168 | public function getRedirectUri(): ?string |
||
| 172 | |||
| 173 | public function setUserAccount(UserAccount $userAccount, bool $isFullyAuthenticated): void |
||
| 178 | |||
| 179 | public function getUserAccount(): ?UserAccount |
||
| 183 | |||
| 184 | public function setResponseParameter(string $responseParameter, $value): void |
||
| 188 | |||
| 189 | public function getResponseParameters(): array |
||
| 193 | |||
| 194 | public function getResponseParameter(string $param) |
||
| 202 | |||
| 203 | public function hasResponseParameter(string $param): bool |
||
| 207 | |||
| 208 | public function setResponseHeader(string $responseHeader, $value): void |
||
| 212 | |||
| 213 | public function getResponseHeaders(): array |
||
| 217 | |||
| 218 | public function isUserAccountFullyAuthenticated(): ?bool |
||
| 222 | |||
| 223 | /** |
||
| 224 | * @return string[] |
||
| 225 | */ |
||
| 226 | public function getPrompt(): array |
||
| 234 | |||
| 235 | public function hasUiLocales(): bool |
||
| 239 | |||
| 240 | /** |
||
| 241 | * @return string[] |
||
| 242 | */ |
||
| 243 | public function getUiLocales(): array |
||
| 247 | |||
| 248 | public function hasPrompt(string $prompt): bool |
||
| 252 | |||
| 253 | public function isAuthorized(): bool |
||
| 257 | |||
| 258 | public function allow(): void |
||
| 262 | |||
| 263 | public function deny(): void |
||
| 267 | |||
| 268 | public function hasData(string $key): bool |
||
| 272 | |||
| 273 | public function getData(string $key) |
||
| 281 | |||
| 282 | public function setData(string $key, $data): void |
||
| 286 | |||
| 287 | public function getResourceServer(): ?ResourceServer |
||
| 291 | |||
| 292 | public function setResourceServer(ResourceServer $resourceServer): void |
||
| 296 | |||
| 297 | public function setConsentScreenOption(string $option, $value): void |
||
| 301 | |||
| 302 | public function unsetConsentScreenOption(string $option): void |
||
| 310 | |||
| 311 | public function hasScope(): bool |
||
| 315 | |||
| 316 | public function getScope(): string |
||
| 320 | |||
| 321 | public function getMetadata(): DataBag |
||
| 325 | } |
||
| 326 |
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
@returnannotation as described here.