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 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 2
nop 1
dl 0
loc 13
rs 9.9666
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 CaptureRequestConverter 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
        $captureRequest = $requestTransfer->getCaptureRequest();
37
        if ($captureRequest === null) {
38
            return [];
39
        }
40
41
        return [
42
            $this->config->getApiFieldMerchantId() => $captureRequest->getMerchantID(),
43
            $this->config->getApiFieldStoreId() => $captureRequest->getStoreID(),
44
            $this->config->getApiFieldOrderId() => $captureRequest->getOrderID(),
45
            $this->config->getApiFieldCaptureId() => $captureRequest->getCaptureID(),
46
            $this->config->getApiFieldAmount() => $this->getAmountData($captureRequest->getAmount()),
47
        ];
48
    }
49
50
    /**
51
     * @param \Generated\Shared\Transfer\CrefoPayApiAmountTransfer|null $amountTransfer
52
     *
53
     * @return array|null
54
     */
55
    protected function getAmountData(?CrefoPayApiAmountTransfer $amountTransfer): ?array
56
    {
57
        return $amountTransfer ? $this->convertAmountTransferToArray($amountTransfer) : null;
58
    }
59
60
    /**
61
     * @param \Generated\Shared\Transfer\CrefoPayApiAmountTransfer $amountTransfer
62
     *
63
     * @return array
64
     */
65
    protected function convertAmountTransferToArray(CrefoPayApiAmountTransfer $amountTransfer): array
66
    {
67
        return [
68
            $this->config->getApiObjectAmountFieldAmount() => $amountTransfer->getAmount(),
69
            $this->config->getApiObjectAmountFieldVatAmount() => $amountTransfer->getVatAmount(),
70
            $this->config->getApiObjectAmountFieldVatRate() => $amountTransfer->getVatRate(),
71
        ];
72
    }
73
}
74