Passed
Push — master ( 981969...7f86a3 )
by Samuel
04:21
created

ClientHandler::clientExceptionCausers()

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
eloc 3
nc 1
nop 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A ClientHandler.php$0 ➔ isPagarme() 0 3 1
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()->isPagarme($requestHost)) {
16
            $pagarMeCode = config($this->configFile.'codes.client.pagarme') ?? $code;
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

16
            $pagarMeCode = /** @scrutinizer ignore-call */ config($this->configFile.'codes.client.pagarme') ?? $code;
Loading history...
Bug Best Practice introduced by
The property configFile does not exist on SMartins\JsonHandler\ClientHandler. Did you maybe forget to declare it?
Loading history...
17
18
            $detail = $detail.' #'.$pagarMeCode;
19
            $code = $pagarMeCode;
20
        }
21
22
        $error = [[
23
            'status'    => 500,
24
            'code'      => $code,
25
            'source'    => ['pointer' => $exception->getFile().':'.$exception->getLine()],
26
            'title'     => 'client_exception',
27
            'detail'    => $detail,
28
        ]];
29
30
        $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...
31
        $this->jsonApiResponse->setErrors($error);
32
    }
33
34
    public function clientExceptionCausers()
35
    {
36
        return new class() {
37
            const PAGARME_HOST = 'api.pagar.me';
38
39
            public function isPagarme($host)
40
            {
41
                return self::PAGARME_HOST == $host;
42
            }
43
        };
44
    }
45
}
46