Passed
Push — master ( ca86ac...981969 )
by Samuel
01:41
created

ClientHandler   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
dl 0
loc 29
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A hp$0 ➔ clientExceptionCausers() 0 4 1
clientExceptionCausers() 0 4 ?
A clientException() 0 21 2
1
<?php
2
3
namespace SMartins\JsonHandler;
4
5
use GuzzleHttp\Exception\ClientException;
0 ignored issues
show
Bug introduced by
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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
7
trait ClientHandler
8
{
9
    public function clientException(ClientException $exception)
10
    {
11
        $requestHost = $exception->getRequest()->getUri()->getHost();
12
13
        $detail = __('exception::exceptions.client.unavailable');
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

13
        $detail = /** @scrutinizer ignore-call */ __('exception::exceptions.client.unavailable');
Loading history...
14
        $code = $this->getCode('client.default');
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

14
        /** @scrutinizer ignore-call */ 
15
        $code = $this->getCode('client.default');
Loading history...
15
        if ($this->clientExceptionCausers()::PAGARME_HOST == $requestHost) {
16
            $detail = $detail;
17
            $code = $this->getCode('client.pagarme');
18
        }
19
20
        $error = [[
21
            'status'    => 500,
22
            'code'      => $code,
23
            'source'    => ['pointer' => $exception->getFile().':'.$exception->getLine()],
24
            'title'     => 'client_exception',
25
            'detail'    => $detail,
26
        ]];
27
28
        $this->jsonApiResponse->setStatus(500);
0 ignored issues
show
Bug Best Practice introduced by
The property jsonApiResponse does not exist on SMartins\JsonHandler\ClientHandler. Did you maybe forget to declare it?
Loading history...
29
        $this->jsonApiResponse->setErrors($error);
30
    }
31
32
    public function clientExceptionCausers()
33
    {
34
        return new class() {
35
            const PAGARME_HOST = 'api.pagar.me';
36
        };
37
    }
38
}
39