Completed
Pull Request — master (#3)
by Aleksey
15:31 queued 12:58
created

CaptureRequestConverter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 44
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getAmountData() 0 3 2
A convertAmountTransferToArray() 0 6 1
A convertRequestTransferToArray() 0 13 2
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\Business\Request\CrefoPayApiRequestFields;
13
14
class CaptureRequestConverter implements CrefoPayApiRequestConverterInterface
15
{
16
    /**
17
     * @param \Generated\Shared\Transfer\CrefoPayApiRequestTransfer $requestTransfer
18
     *
19
     * @return array
20
     */
21
    public function convertRequestTransferToArray(CrefoPayApiRequestTransfer $requestTransfer): array
22
    {
23
        $captureRequest = $requestTransfer->getCaptureRequest();
24
        if ($captureRequest === null) {
25
            return [];
26
        }
27
28
        return [
29
            CrefoPayApiRequestFields::API_FIELD_MERCHANT_ID => $captureRequest->getMerchantID(),
30
            CrefoPayApiRequestFields::API_FIELD_STORE_ID => $captureRequest->getStoreID(),
31
            CrefoPayApiRequestFields::API_FIELD_ORDER_ID => $captureRequest->getOrderID(),
32
            CrefoPayApiRequestFields::API_FIELD_CAPTURE_ID => $captureRequest->getCaptureID(),
33
            CrefoPayApiRequestFields::API_FIELD_AMOUNT => $this->getAmountData($captureRequest->getAmount()),
34
        ];
35
    }
36
37
    /**
38
     * @param \Generated\Shared\Transfer\CrefoPayApiAmountTransfer|null $amountTransfer
39
     *
40
     * @return array|null
41
     */
42
    protected function getAmountData(?CrefoPayApiAmountTransfer $amountTransfer): ?array
43
    {
44
        return $amountTransfer ? $this->convertAmountTransferToArray($amountTransfer) : null;
45
    }
46
47
    /**
48
     * @param \Generated\Shared\Transfer\CrefoPayApiAmountTransfer $amountTransfer
49
     *
50
     * @return array
51
     */
52
    protected function convertAmountTransferToArray(CrefoPayApiAmountTransfer $amountTransfer): array
53
    {
54
        return [
55
            CrefoPayApiRequestFields::API_OBJECT_AMOUNT_FIELD_AMOUNT => $amountTransfer->getAmount(),
56
            CrefoPayApiRequestFields::API_OBJECT_AMOUNT_FIELD_VAT_AMOUNT => $amountTransfer->getVatAmount(),
57
            CrefoPayApiRequestFields::API_OBJECT_AMOUNT_FIELD_VAT_RATE => $amountTransfer->getVatRate(),
58
        ];
59
    }
60
}
61