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

convertRequestTransferToArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 1
dl 0
loc 14
rs 9.9332
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\Request\Converter;
9
10
use Generated\Shared\Transfer\CrefoPayApiAmountTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...efoPayApiAmountTransfer 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\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...
12
use SprykerEco\Zed\CrefoPayApi\CrefoPayApiConfig;
13
14
class RefundRequestConverter implements CrefoPayApiRequestConverterInterface
15
{
16
    /**
17
     * @var \SprykerEco\Zed\CrefoPayApi\CrefoPayApiConfig
18
     */
19
    protected $config;
20
21
    /**
22
     * @param \SprykerEco\Zed\CrefoPayApi\CrefoPayApiConfig $config
23
     */
24
    public function __construct(CrefoPayApiConfig $config)
25
    {
26
        $this->config = $config;
27
    }
28
29
    /**
30
     * @param \Generated\Shared\Transfer\CrefoPayApiRequestTransfer $requestTransfer
31
     *
32
     * @return array
33
     */
34
    public function convertRequestTransferToArray(CrefoPayApiRequestTransfer $requestTransfer): array
35
    {
36
        $refundRequest = $requestTransfer->getRefundRequest();
37
        if ($refundRequest === null) {
38
            return [];
39
        }
40
41
        return [
42
            $this->config->getApiFieldMerchantId() => $refundRequest->getMerchantID(),
43
            $this->config->getApiFieldStoreId() => $refundRequest->getStoreID(),
44
            $this->config->getApiFieldOrderId() => $refundRequest->getOrderID(),
45
            $this->config->getApiFieldCaptureId() => $refundRequest->getCaptureID(),
46
            $this->config->getApiFieldAmount() => $this->getAmountData($refundRequest->getAmount()),
47
            $this->config->getApiFieldRefundDescription() => $refundRequest->getRefundDescription(),
48
        ];
49
    }
50
51
    /**
52
     * @param \Generated\Shared\Transfer\CrefoPayApiAmountTransfer|null $amountTransfer
53
     *
54
     * @return array|null
55
     */
56
    protected function getAmountData(?CrefoPayApiAmountTransfer $amountTransfer): ?array
57
    {
58
        return $amountTransfer ? $this->convertAmountTransferToArray($amountTransfer) : null;
59
    }
60
61
    /**
62
     * @param \Generated\Shared\Transfer\CrefoPayApiAmountTransfer $amountTransfer
63
     *
64
     * @return array
65
     */
66
    protected function convertAmountTransferToArray(CrefoPayApiAmountTransfer $amountTransfer): array
67
    {
68
        return [
69
            $this->config->getApiObjectAmountFieldAmount() => $amountTransfer->getAmount(),
70
            $this->config->getApiObjectAmountFieldVatAmount() => $amountTransfer->getVatAmount(),
71
            $this->config->getApiObjectAmountFieldVatRate() => $amountTransfer->getVatRate(),
72
        ];
73
    }
74
}
75