Passed
Push — feature/eco-2295/eco-2344-crea... ( 1e5ae0...217e63 )
by Aleksey
01:02
created

CrefoPayApiClient   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 16
dl 0
loc 44
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getMethod() 0 3 1
A performRequest() 0 18 3
1
<?php
2
3
/**
4
 * MIT License
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
namespace SprykerEco\Zed\CrefoPayApi\Business\Client;
9
10
use Generated\Shared\Transfer\CrefoPayApiRequestTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...foPayApiRequestTransfer 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...
11
use Generated\Shared\Transfer\CrefoPayApiResponseTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...oPayApiResponseTransfer 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...
12
use GuzzleHttp\Exception\RequestException;
0 ignored issues
show
Bug introduced by
The type GuzzleHttp\Exception\RequestException 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...
13
use Spryker\Shared\Kernel\Transfer\Exception\RequiredTransferPropertyException;
0 ignored issues
show
Bug introduced by
The type Spryker\Shared\Kernel\Tr...ansferPropertyException 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...
14
15
class CrefoPayApiClient implements CrefoPayApiClientInterface
16
{
17
    /**
18
     * @var \GuzzleHttp\ClientInterface
0 ignored issues
show
Bug introduced by
The type GuzzleHttp\ClientInterface 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...
19
     */
20
    protected $client;
21
22
    /**
23
     * @var \SprykerEco\Zed\CrefoPayApi\Business\Request\CrefoPayApiRequestInterface
24
     */
25
    protected $request;
26
27
    /**
28
     * @var \SprykerEco\Zed\CrefoPayApi\Business\Converter\CrefoPayApiConverterInterface
29
     */
30
    protected $converter;
31
32
    public function performRequest(CrefoPayApiRequestTransfer $requestTransfer): CrefoPayApiResponseTransfer
33
    {
34
        $method = $this->getMethod();
35
36
        try {
37
            /** @var \Psr\Http\Message\ResponseInterface $response */
38
            $response = $this->client->$method(
39
                $this->request->getUrl(),
40
                $this->request->getRequestOptions($requestTransfer)
41
            );
42
43
            return $this->converter->convertToResponseTransfer($response);
44
45
        } catch (RequestException $requestException) {
46
            $response = $requestException->getResponse();
0 ignored issues
show
Unused Code introduced by
The assignment to $response is dead and can be removed.
Loading history...
47
            return;
0 ignored issues
show
Bug Best Practice introduced by
The expression return returns the type null which is incompatible with the type-hinted return Generated\Shared\Transfe...oPayApiResponseTransfer.
Loading history...
48
        } catch (RequiredTransferPropertyException $requiredTransferPropertyException) {
49
            return;
0 ignored issues
show
Bug Best Practice introduced by
The expression return returns the type null which is incompatible with the type-hinted return Generated\Shared\Transfe...oPayApiResponseTransfer.
Loading history...
50
        }
51
    }
52
53
    /**
54
     * @return string
55
     */
56
    protected function getMethod(): string
57
    {
58
        return strtolower($this->request->getHttpMethod());
59
    }
60
}