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

CrefoPayApiClient::performRequest()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 25
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 16
nc 2
nop 1
dl 0
loc 25
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
     * @param \Generated\Shared\Transfer\CrefoPayApiRequestTransfer $requestTransfer
60
     *
61
     * @return \Generated\Shared\Transfer\CrefoPayApiResponseTransfer
62
     */
63
    public function performRequest(CrefoPayApiRequestTransfer $requestTransfer): CrefoPayApiResponseTransfer
64
    {
65
        $isSuccess = true;
66
67
        try {
68
            $response = $this->httpClient->post(
69
                $this->request->getUrl(),
70
                $this->request->getFormParams($requestTransfer)
71
            );
72
        } catch (CrefoPayApiGuzzleRequestException $requestException) {
73
            $isSuccess = false;
74
            $response = $requestException->getResponse();
75
        }
76
77
        $responseTransfer = $this->converter->convertToResponseTransfer($response, $isSuccess);
78
        $paymentCrefoPayApiLogTransfer = $this->logger
79
            ->logApiCall(
80
                $requestTransfer,
81
                $responseTransfer,
82
                $this->request->getRequestType()
83
            );
84
85
        $responseTransfer->setCrefoPayApiLogId($paymentCrefoPayApiLogTransfer->getIdPaymentCrefoPayApiLog());
86
87
        return $responseTransfer;
88
    }
89
}
90