Conditions | 1 |
Paths | 1 |
Total Lines | 59 |
Code Lines | 37 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
35 | public function execute(TestInfo $testInfo): void |
||
36 | { |
||
37 | $jwkSig = JWKFactory::createRSAKey(2048, ['alg' => 'RS256', 'use' => 'sig']); |
||
38 | $jwkEncAlg = JWKFactory::createRSAKey(2048, ['alg' => 'RSA-OAEP', 'use' => 'enc']); |
||
39 | |||
40 | $jwks = new JWKSet([$jwkSig, $jwkEncAlg]); |
||
41 | $publicJwks = new JWKSet(\array_map(static function (JWK $jwk) { |
||
42 | return $jwk->toPublic(); |
||
43 | }, $jwks->all())); |
||
44 | |||
45 | $client = $this->registerClient($testInfo, [ |
||
46 | 'request_object_signing_alg' => 'RS256', |
||
47 | 'request_object_encryption_alg' => 'RSA-OAEP', |
||
48 | 'request_object_encryption_enc' => 'A128CBC-HS256', |
||
49 | 'jwks' => json_decode(json_encode($publicJwks), true), |
||
50 | ], $jwks); |
||
51 | |||
52 | Assert::assertSame('RS256', $client->getMetadata()->get('request_object_signing_alg')); |
||
53 | Assert::assertSame('RSA-OAEP', $client->getMetadata()->get('request_object_encryption_alg')); |
||
54 | Assert::assertSame('A128CBC-HS256', $client->getMetadata()->get('request_object_encryption_enc')); |
||
55 | |||
56 | // Get authorization redirect uri |
||
57 | $requestObjectFactory = new RequestObjectFactory(); |
||
58 | $authorizationService = new AuthorizationService(); |
||
|
|||
59 | |||
60 | $authSession = AuthSession::fromArray([ |
||
61 | 'state' => base64url_encode(\random_bytes(32)), |
||
62 | 'nonce' => base64url_encode(\random_bytes(32)), |
||
63 | ]); |
||
64 | $uri = $authorizationService->getAuthorizationUri($client, [ |
||
65 | 'request' => $requestObjectFactory->create($client), |
||
66 | 'state' => $authSession->getState(), |
||
67 | 'nonce' => $authSession->getNonce(), |
||
68 | ]); |
||
69 | |||
70 | // Simulate a redirect and create the server request |
||
71 | $serverRequest = $this->simulateAuthRedirect($uri, 'application/jwt'); |
||
72 | |||
73 | $params = $authorizationService->getCallbackParams($serverRequest, $client); |
||
74 | $tokenSet = $authorizationService->callback($client, $params, null, $authSession); |
||
75 | |||
76 | Assert::assertNotNull($tokenSet->getState()); |
||
77 | |||
78 | // update issuer JWKSet |
||
79 | $client->getIssuer()->getJwksProvider()->reload(); |
||
80 | |||
81 | $uri = $authorizationService->getAuthorizationUri($client, [ |
||
82 | 'request' => $requestObjectFactory->create($client), |
||
83 | 'state' => $authSession->getState(), |
||
84 | 'nonce' => $authSession->getNonce(), |
||
85 | ]); |
||
86 | |||
87 | // Simulate a redirect and create the server request |
||
88 | $serverRequest = $this->simulateAuthRedirect($uri); |
||
89 | |||
90 | $params = $authorizationService->getCallbackParams($serverRequest, $client); |
||
91 | $tokenSet = $authorizationService->callback($client, $params, null, $authSession); |
||
92 | |||
93 | Assert::assertNotNull($tokenSet->getIdToken()); |
||
94 | } |
||
96 |
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.