Conditions | 12 |
Paths | 19 |
Total Lines | 50 |
Code Lines | 32 |
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 |
||
56 | public function authenticate(ServerRequestInterface $request): ClientInterface |
||
57 | { |
||
58 | $identifier = null; |
||
59 | $password = null; |
||
60 | $useHTTPAuthenticationScheme = true; |
||
61 | $body = $request->getParsedBody(); |
||
62 | if ($request->hasHeader('Authorization')) { |
||
63 | // 2.3 The client MUST NOT use more than one authentication method in each request |
||
64 | if (isset($body['client_secret'])) { |
||
65 | throw new \Exception('Multiple authentication methods used'); |
||
66 | } |
||
67 | |||
68 | $authorization = $request->getHeader('Authorization')[0] ?? ''; |
||
69 | $authorization = explode(' ', trim($authorization)); |
||
70 | $method = $authorization[0]; |
||
71 | if (strtolower($method) === 'basic') { |
||
72 | $authorization = explode(':', base64_decode($authorization[1])); |
||
73 | $identifier = $authorization[0] ?? null; |
||
74 | $password = $authorization[1] ?? ''; |
||
75 | } |
||
76 | } else { |
||
77 | $identifier = $body['client_id'] ?? null; |
||
78 | $password = $body['client_secret'] ?? ''; |
||
79 | $useHTTPAuthenticationScheme = false; |
||
80 | } |
||
81 | |||
82 | if (is_null($identifier)) { |
||
83 | throw new \Exception('No client authentication included'); |
||
84 | } |
||
85 | |||
86 | $client = $this->clientStorage->get($identifier); |
||
87 | if (!$client) { |
||
88 | throw new \Exception('Unknown client'); |
||
89 | } |
||
90 | |||
91 | if (!$useHTTPAuthenticationScheme && |
||
92 | ($this->supportCredentialsInBody === false || |
||
93 | (is_null($this->supportCredentialsInBody) && $client->isHttpBasicAuthenticationSchemeSupported()))) { |
||
94 | throw new \Exception('Authentication method is limited to HTTP Basic authentication scheme'); |
||
95 | } |
||
96 | |||
97 | if (!$client instanceof ConfidentialClientInterface) { |
||
98 | throw new \Exception('Unsupported authentication method'); |
||
99 | } |
||
100 | |||
101 | if ($client->getPassword() !== $password) { |
||
102 | throw new \Exception('Authentication failed'); |
||
103 | } |
||
104 | |||
105 | return $client; |
||
106 | } |
||
107 | } |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths