sfelix-martins /
json-exception-handler
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | namespace SMartins\JsonHandler; |
||||||
| 4 | |||||||
| 5 | use Illuminate\Support\Facades\App; |
||||||
|
0 ignored issues
–
show
|
|||||||
| 6 | use GuzzleHttp\Exception\ClientException; |
||||||
|
0 ignored issues
–
show
The type
GuzzleHttp\Exception\ClientException was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||||
| 7 | |||||||
| 8 | trait ClientHandler |
||||||
| 9 | { |
||||||
| 10 | public function clientException($exception) |
||||||
| 11 | { |
||||||
| 12 | $statusCode = 500; |
||||||
| 13 | $title = 'client_exception'; |
||||||
| 14 | $detail = $exception->getMessage(); |
||||||
| 15 | $code = $this->getCode(); |
||||||
|
0 ignored issues
–
show
It seems like
getCode() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 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'; |
||||||
|
0 ignored issues
–
show
The function
config was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 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; |
||||||
|
0 ignored issues
–
show
The function
__ was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 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); |
||||||
|
0 ignored issues
–
show
|
|||||||
| 60 | $this->jsonApiResponse->setErrors($error); |
||||||
| 61 | } |
||||||
| 62 | |||||||
| 63 | public function clientExceptionCausers() |
||||||
| 64 | { |
||||||
| 65 | return new class() { |
||||||
| 66 | const PAGARME_HOST = 'api.pagar.me'; |
||||||
| 67 | |||||||
| 68 | const MAILGUN_HOST = 'api.mailgun.net'; |
||||||
| 69 | |||||||
| 70 | public function isPagarme($host) |
||||||
| 71 | { |
||||||
| 72 | return self::PAGARME_HOST == $host; |
||||||
| 73 | } |
||||||
| 74 | |||||||
| 75 | public function isMailgun($host) |
||||||
| 76 | { |
||||||
| 77 | return self::MAILGUN_HOST == $host; |
||||||
| 78 | } |
||||||
| 79 | }; |
||||||
| 80 | } |
||||||
| 81 | } |
||||||
| 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