Conditions | 10 |
Paths | 13 |
Total Lines | 34 |
Code Lines | 21 |
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 |
||
33 | public function handle(ClientId $clientId, DataBag $commandParameters, DataBag $validatedParameters, RuleHandler $next): DataBag |
||
34 | { |
||
35 | if ($commandParameters->has('jwks') && $commandParameters->has('jwks_uri')) { |
||
36 | throw new \InvalidArgumentException('The parameters "jwks" and "jwks_uri" cannot be set together.'); |
||
37 | } |
||
38 | |||
39 | if ($commandParameters->has('jwks')) { |
||
40 | try { |
||
41 | $keyset = JWKSet::createFromKeyData($commandParameters->get('jwks')); |
||
|
|||
42 | } catch (\Throwable $e) { |
||
43 | throw new \InvalidArgumentException('The parameter "jwks" must be a valid JWKSet object.', 0, $e); |
||
44 | } |
||
45 | if (0 === \count($keyset)) { |
||
46 | throw new \InvalidArgumentException('The parameter "jwks" must not be empty.'); |
||
47 | } |
||
48 | $validatedParameters->set('jwks', $commandParameters->get('jwks')); |
||
49 | } |
||
50 | if ($commandParameters->has('jwks_uri')) { |
||
51 | if (null === $this->jkuFactory) { |
||
52 | throw new \InvalidArgumentException('Distant key sets cannot be used. Please use "jwks" instead of "jwks_uri".'); |
||
53 | } |
||
54 | |||
55 | try { |
||
56 | $jwks = $this->jkuFactory->loadFromUrl($commandParameters->get('jwks_uri')); |
||
57 | } catch (\Throwable $e) { |
||
58 | throw new \InvalidArgumentException('The parameter "jwks_uri" must be a valid uri to a JWKSet.', 0, $e); |
||
59 | } |
||
60 | if (0 === $jwks->count()) { |
||
61 | throw new \InvalidArgumentException('The distant key set is empty.'); |
||
62 | } |
||
63 | $validatedParameters->set('jwks_uri', $commandParameters->get('jwks_uri')); |
||
64 | } |
||
65 | |||
66 | return $next->handle($clientId, $commandParameters, $validatedParameters); |
||
67 | } |
||
69 |