Passed
Push — feature/eco-2295/eco-2344-crea... ( 83a5ab...226db0 )
by Aleksey
01:13
created

CrefoPayApiClient::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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\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...
13
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...
14
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...
15
16
class CrefoPayApiClient implements CrefoPayApiClientInterface
17
{
18
    /**
19
     * @var \GuzzleHttp\ClientInterface
20
     */
21
    protected $client;
22
23
    /**
24
     * @var \SprykerEco\Zed\CrefoPayApi\Business\Request\CrefoPayApiRequestInterface
25
     */
26
    protected $request;
27
28
    /**
29
     * @var \SprykerEco\Zed\CrefoPayApi\Business\Converter\CrefoPayApiConverterInterface
30
     */
31
    protected $converter;
32
33
    public function __construct(
34
        ClientInterface $client
35
    ) {
36
        $this->client = $client;
37
    }
38
39
    /**
40
     * @param \Generated\Shared\Transfer\CrefoPayApiRequestTransfer $requestTransfer
41
     *
42
     * @return \Generated\Shared\Transfer\CrefoPayApiResponseTransfer
43
     */
44
    public function performRequest(CrefoPayApiRequestTransfer $requestTransfer): CrefoPayApiResponseTransfer
45
    {
46
        $method = $this->getMethod();
47
48
        try {
49
            /** @var \Psr\Http\Message\ResponseInterface $response */
50
            $response = $this->client->$method(
51
                $this->request->getUrl(),
52
                $this->request->getRequestOptions($requestTransfer)
53
            );
54
55
            return $this->converter->convertToResponseTransfer($response);
56
57
        } catch (RequestException $requestException) {
58
            $response = $requestException->getResponse();
0 ignored issues
show
Unused Code introduced by
The assignment to $response is dead and can be removed.
Loading history...
59
            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...
60
        } catch (RequiredTransferPropertyException $requiredTransferPropertyException) {
61
            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...
62
        }
63
    }
64
65
    /**
66
     * @return string
67
     */
68
    protected function getMethod(): string
69
    {
70
        return strtolower($this->request->getHttpMethod());
71
    }
72
}