Passed
Push — feature/eco-2295/eco-2344-crea... ( 946f77...8dc4d0 )
by Aleksey
01:38
created

CrefoPayApiClient::getMethod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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