Passed
Pull Request — feature/eco-2295/dev (#1)
by Aleksey
02:03 queued 01:01
created

CrefoPayApiClient::performRequest()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 26
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 16
nc 2
nop 1
dl 0
loc 26
rs 9.7333
c 0
b 0
f 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 SprykerEco\Zed\CrefoPayApi\Business\Converter\CrefoPayApiConverterInterface;
13
use SprykerEco\Zed\CrefoPayApi\Business\Logger\CrefoPayApiLoggerInterface;
14
use SprykerEco\Zed\CrefoPayApi\Business\Request\CrefoPayApiRequestInterface;
15
use SprykerEco\Zed\CrefoPayApi\Dependency\External\Guzzle\CrefoPayApiGuzzleHttpClientAdapterInterface;
16
use SprykerEco\Zed\CrefoPayApi\Dependency\External\Guzzle\Exception\CrefoPayApiGuzzleRequestException;
17
18
class CrefoPayApiClient implements CrefoPayApiClientInterface
19
{
20
    /**
21
     * @var \SprykerEco\Zed\CrefoPayApi\Dependency\External\Guzzle\CrefoPayApiGuzzleHttpClientAdapterInterface
22
     */
23
    protected $httpClient;
24
25
    /**
26
     * @var \SprykerEco\Zed\CrefoPayApi\Business\Request\CrefoPayApiRequestInterface
27
     */
28
    protected $request;
29
30
    /**
31
     * @var \SprykerEco\Zed\CrefoPayApi\Business\Converter\CrefoPayApiConverterInterface
32
     */
33
    protected $converter;
34
35
    /**
36
     * @var \SprykerEco\Zed\CrefoPayApi\Business\Logger\CrefoPayApiLoggerInterface
37
     */
38
    protected $logger;
39
40
    /**
41
     * @param \SprykerEco\Zed\CrefoPayApi\Dependency\External\Guzzle\CrefoPayApiGuzzleHttpClientAdapterInterface $httpClient
42
     * @param \SprykerEco\Zed\CrefoPayApi\Business\Request\CrefoPayApiRequestInterface $request
43
     * @param \SprykerEco\Zed\CrefoPayApi\Business\Converter\CrefoPayApiConverterInterface $converter
44
     * @param \SprykerEco\Zed\CrefoPayApi\Business\Logger\CrefoPayApiLoggerInterface $logger
45
     */
46
    public function __construct(
47
        CrefoPayApiGuzzleHttpClientAdapterInterface $httpClient,
48
        CrefoPayApiRequestInterface $request,
49
        CrefoPayApiConverterInterface $converter,
50
        CrefoPayApiLoggerInterface $logger
51
    ) {
52
        $this->httpClient = $httpClient;
53
        $this->request = $request;
54
        $this->converter = $converter;
55
        $this->logger = $logger;
56
57
    }
58
59
    /**
60
     * @param \Generated\Shared\Transfer\CrefoPayApiRequestTransfer $requestTransfer
61
     *
62
     * @return \Generated\Shared\Transfer\CrefoPayApiResponseTransfer
63
     */
64
    public function performRequest(CrefoPayApiRequestTransfer $requestTransfer): CrefoPayApiResponseTransfer
65
    {
66
        $isSuccess = true;
67
68
        try {
69
            $response = $this->httpClient->post(
70
                $this->request->getUrl(),
71
                $this->request->getFormParams($requestTransfer)
72
            );
73
74
        } catch (CrefoPayApiGuzzleRequestException $requestException) {
75
            $isSuccess = false;
76
            $response = $requestException->getResponse();
77
        }
78
79
        $responseTransfer = $this->converter->convertToResponseTransfer($response, $isSuccess);
80
        $paymentCrefoPayApiLogTransfer = $this->logger
81
            ->logApiCall(
82
                $requestTransfer,
83
                $responseTransfer,
84
                $this->request->getRequestType()
85
            );
86
87
        $responseTransfer->setCrefoPayApiLogId($paymentCrefoPayApiLogTransfer->getIdPaymentCrefoPayApiLog());
88
89
        return $responseTransfer;
90
    }
91
}