Conditions | 12 |
Paths | 13 |
Total Lines | 35 |
Code Lines | 20 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
50 | public function authenticate(ServerRequestInterface $request): bool |
||
51 | { |
||
52 | $clientAuthenticatorSupported = null; |
||
53 | /** |
||
54 | * @var ClientAuthenticatorInterface $clientAuthenticator |
||
55 | */ |
||
56 | foreach ($this->server->getClientAuthenticatorRepository()->getClientAuthenticators() as $clientAuthenticator) { |
||
57 | if ($clientAuthenticator->support($request)) { |
||
58 | if ($clientAuthenticatorSupported) { |
||
59 | throw new OAuthException('invalid_client', 'Multiple authentication methods used', |
||
60 | 'https://tools.ietf.org/html/rfc6749#section-5.2'); |
||
61 | } |
||
62 | $clientAuthenticatorSupported = $clientAuthenticator; |
||
63 | } |
||
64 | } |
||
65 | |||
66 | if (!$clientAuthenticatorSupported) { |
||
67 | return false; |
||
68 | } |
||
69 | |||
70 | try { |
||
71 | $this->client = $clientAuthenticatorSupported->authenticate($request); |
||
72 | } catch (\Exception $e) { |
||
73 | throw new OAuthException('invalid_client', $e->getMessage(), |
||
74 | 'https://tools.ietf.org/html/rfc6749#section-5.2'); |
||
75 | } |
||
76 | |||
77 | if (($this->enforceTLS === true && !$this->server->isSecure()) || |
||
78 | (is_null($this->enforceTLS) && $clientAuthenticatorSupported->isPasswordAuthentication() && |
||
79 | !$this->server->isSecure() && $this->client->isTLSSupported())) { |
||
80 | throw new OAuthException('access_denied', 'Require the use of TLS', |
||
81 | 'https://tools.ietf.org/html/rfc6749#section-3.1.2.1'); |
||
82 | } |
||
83 | |||
84 | return true; |
||
85 | } |
||
102 | } |