Conditions | 6 |
Paths | 9 |
Total Lines | 51 |
Code Lines | 34 |
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 |
||
10 | public function clientException($exception) |
||
11 | { |
||
12 | $statusCode = 500; |
||
13 | $title = 'client_exception'; |
||
14 | $detail = $exception->getMessage(); |
||
15 | $code = $this->getCode(); |
||
16 | |||
17 | if ($exception instanceof ClientException) { |
||
18 | $requestHost = $exception->getRequest()->getUri()->getHost(); |
||
19 | $clientCausers = $this->clientExceptionCausers(); |
||
20 | |||
21 | $response = $exception->getResponse(); |
||
22 | |||
23 | if ($clientCausers->isPagarme($requestHost)) { |
||
24 | $code = config('json-exception-handler.codes.client.pagarme') ?? 'pagarme'; |
||
25 | $errors = json_decode($response->getBody())->errors; |
||
26 | |||
27 | $firstErrorMessage = ''; |
||
28 | foreach ($errors as $error) { |
||
29 | $firstErrorMessage = $error->message; |
||
30 | break; |
||
31 | } |
||
32 | |||
33 | $detailedError = $firstErrorMessage.' #'.$code; |
||
34 | } elseif ($clientCausers->isMailgun($requestHost)) { |
||
35 | $code = config('json-exception-handler.codes.client.mailgun') ?? 'mailgun'; |
||
36 | $detailedError = json_decode($response->getBody())->message.' #'.$code; |
||
37 | } else { |
||
38 | // Unknown error |
||
39 | $code = config('json-exception-handler.codes.client.default'); |
||
40 | } |
||
41 | |||
42 | if (App::environment('production')) { |
||
43 | $detail = __('exception::exceptions.client.unavailable').' #'.$code; |
||
44 | } else { |
||
45 | // Return more details about error |
||
46 | $detail = $detailedError ?? $detail; |
||
47 | $statusCode = $response->getStatusCode(); |
||
48 | } |
||
49 | } |
||
50 | |||
51 | $error = [[ |
||
52 | 'status' => $statusCode, |
||
53 | 'code' => $code, |
||
54 | 'source' => ['pointer' => $exception->getFile().':'.$exception->getLine()], |
||
55 | 'title' => $title, |
||
56 | 'detail' => $detail, |
||
57 | ]]; |
||
58 | |||
59 | $this->jsonApiResponse->setStatus($statusCode); |
||
60 | $this->jsonApiResponse->setErrors($error); |
||
61 | } |
||
82 |
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