Complex classes like ClientAssertionJwt 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 ClientAssertionJwt, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
34 | class ClientAssertionJwt implements AuthenticationMethod |
||
35 | { |
||
36 | private const CLIENT_ASSERTION_TYPE = 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer'; |
||
37 | |||
38 | /** |
||
39 | * @var JWSVerifier |
||
40 | */ |
||
41 | private $jwsVerifier; |
||
42 | |||
43 | /** |
||
44 | * @var null|TrustedIssuerRepository |
||
45 | */ |
||
46 | private $trustedIssuerRepository = null; |
||
47 | |||
48 | /** |
||
49 | * @var null|JKUFactory |
||
50 | */ |
||
51 | private $jkuFactory = null; |
||
52 | |||
53 | /** |
||
54 | * @var null|JWELoader |
||
55 | */ |
||
56 | private $jweLoader = null; |
||
57 | |||
58 | /** |
||
59 | * @var null|JWKSet |
||
60 | */ |
||
61 | private $keyEncryptionKeySet = null; |
||
62 | |||
63 | /** |
||
64 | * @var bool |
||
65 | */ |
||
66 | private $encryptionRequired = false; |
||
67 | |||
68 | /** |
||
69 | * @var int |
||
70 | */ |
||
71 | private $secretLifetime; |
||
72 | |||
73 | /** |
||
74 | * @var HeaderCheckerManager |
||
75 | */ |
||
76 | private $headerCheckerManager; |
||
77 | |||
78 | /** |
||
79 | * @var ClaimCheckerManager |
||
80 | */ |
||
81 | private $claimCheckerManager; |
||
82 | |||
83 | /** |
||
84 | * @var JsonConverter |
||
85 | */ |
||
86 | private $jsonConverter; |
||
87 | |||
88 | /** |
||
89 | * ClientAssertionJwt constructor. |
||
90 | * |
||
91 | * @param JsonConverter $jsonConverter |
||
92 | * @param JWSVerifier $jwsVerifier |
||
93 | * @param HeaderCheckerManager $headerCheckerManager |
||
94 | * @param ClaimCheckerManager $claimCheckerManager |
||
95 | * @param int $secretLifetime |
||
96 | */ |
||
97 | public function __construct(JsonConverter $jsonConverter, JWSVerifier $jwsVerifier, HeaderCheckerManager $headerCheckerManager, ClaimCheckerManager $claimCheckerManager, int $secretLifetime = 0) |
||
108 | |||
109 | /** |
||
110 | * @param TrustedIssuerRepository $trustedIssuerRepository |
||
111 | */ |
||
112 | public function enableTrustedIssuerSupport(TrustedIssuerRepository $trustedIssuerRepository) |
||
116 | |||
117 | /** |
||
118 | * @param JKUFactory $jkuFactory |
||
119 | */ |
||
120 | public function enableJkuSupport(JKUFactory $jkuFactory) |
||
124 | |||
125 | /** |
||
126 | * @param JWELoader $jweLoader |
||
127 | * @param JWKSet $keyEncryptionKeySet |
||
128 | * @param bool $encryptionRequired |
||
129 | */ |
||
130 | public function enableEncryptedAssertions(JWELoader $jweLoader, JWKSet $keyEncryptionKeySet, bool $encryptionRequired) |
||
136 | |||
137 | /** |
||
138 | * @return string[] |
||
139 | */ |
||
140 | public function getSupportedSignatureAlgorithms(): array |
||
144 | |||
145 | /** |
||
146 | * @return string[] |
||
147 | */ |
||
148 | public function getSupportedContentEncryptionAlgorithms(): array |
||
152 | |||
153 | /** |
||
154 | * @return string[] |
||
155 | */ |
||
156 | public function getSupportedKeyEncryptionAlgorithms(): array |
||
160 | |||
161 | /** |
||
162 | * {@inheritdoc} |
||
163 | */ |
||
164 | public function getSchemesParameters(): array |
||
168 | |||
169 | /** |
||
170 | * {@inheritdoc} |
||
171 | */ |
||
172 | public function findClientIdAndCredentials(ServerRequestInterface $request, &$clientCredentials = null): ? ClientId |
||
211 | |||
212 | /** |
||
213 | * @param string $assertion |
||
214 | * |
||
215 | * @return string |
||
216 | * |
||
217 | * @throws OAuth2Exception |
||
218 | */ |
||
219 | private function tryToDecryptClientAssertion(string $assertion): string |
||
240 | |||
241 | /** |
||
242 | * {@inheritdoc} |
||
243 | */ |
||
244 | public function isClientAuthenticated(Client $client, $clientCredentials, ServerRequestInterface $request): bool |
||
259 | |||
260 | /** |
||
261 | * {@inheritdoc} |
||
262 | */ |
||
263 | public function getSupportedMethods(): array |
||
267 | |||
268 | /** |
||
269 | * {@inheritdoc} |
||
270 | */ |
||
271 | public function checkClientConfiguration(DataBag $commandParameters, DataBag $validatedParameters): DataBag |
||
282 | |||
283 | /** |
||
284 | * @param DataBag $commandParameters |
||
285 | * @param DataBag $validatedParameters |
||
286 | * |
||
287 | * @return DataBag |
||
288 | */ |
||
289 | private function processClientSecretJwtConfiguration(DataBag $commandParameters, DataBag $validatedParameters): DataBag |
||
297 | |||
298 | /** |
||
299 | * @param DataBag $commandParameters |
||
300 | * @param DataBag $validatedParameters |
||
301 | * |
||
302 | * @return DataBag |
||
303 | */ |
||
304 | private function processPrivateKeyJwtConfiguration(DataBag $commandParameters, DataBag $validatedParameters): DataBag |
||
345 | |||
346 | /** |
||
347 | * @return string |
||
348 | */ |
||
349 | private function createClientSecret(): string |
||
353 | |||
354 | /** |
||
355 | * @param Client $client |
||
356 | * @param JWS $jws |
||
357 | * @param array $claims |
||
358 | * |
||
359 | * @return JWKSet |
||
360 | */ |
||
361 | private function retrieveIssuerKeySet(Client $client, JWS $jws, array $claims): JWKSet |
||
382 | |||
383 | /** |
||
384 | * @param Client $client |
||
385 | * |
||
386 | * @return JWKSet |
||
387 | */ |
||
388 | private function getClientKeySet(Client $client): JWKSet |
||
407 | } |
||
408 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.