Passed
Pull Request — feature/eco-2295/master (#5)
by Aleksey
07:30 queued 03:56
created

RefundOmsCommandRequestBuilder   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 70
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A createAmountTransfer() 0 4 1
A buildRequestTransfer() 0 7 1
A createRefundRequestTransfer() 0 15 1
A getRefundDescription() 0 3 1
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\CrefoPay\Business\Oms\Command\Builder;
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\CrefoPayApiRefundRequestTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...piRefundRequestTransfer 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 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...
13
use Generated\Shared\Transfer\CrefoPayOmsCommandTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...foPayOmsCommandTransfer 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...
14
use SprykerEco\Zed\CrefoPay\CrefoPayConfig;
15
16
class RefundOmsCommandRequestBuilder implements CrefoPayOmsCommandRequestBuilderInterface
17
{
18
    /**
19
     * @var \SprykerEco\Zed\CrefoPay\CrefoPayConfig
20
     */
21
    protected $config;
22
23
    /**
24
     * @param \SprykerEco\Zed\CrefoPay\CrefoPayConfig $config
25
     */
26
    public function __construct(CrefoPayConfig $config)
27
    {
28
        $this->config = $config;
29
    }
30
31
    /**
32
     * @param \Generated\Shared\Transfer\CrefoPayOmsCommandTransfer $crefoPayOmsCommandTransfer
33
     *
34
     * @return \Generated\Shared\Transfer\CrefoPayOmsCommandTransfer
35
     */
36
    public function buildRequestTransfer(CrefoPayOmsCommandTransfer $crefoPayOmsCommandTransfer): CrefoPayOmsCommandTransfer
37
    {
38
        $requestTransfer = (new CrefoPayApiRequestTransfer())
39
            ->setRefundRequest($this->createRefundRequestTransfer($crefoPayOmsCommandTransfer));
40
41
        return $crefoPayOmsCommandTransfer
42
            ->setRequest($requestTransfer);
43
    }
44
45
    /**
46
     * @param \Generated\Shared\Transfer\CrefoPayOmsCommandTransfer $crefoPayOmsCommandTransfer
47
     *
48
     * @return \Generated\Shared\Transfer\CrefoPayApiRefundRequestTransfer
49
     */
50
    protected function createRefundRequestTransfer(CrefoPayOmsCommandTransfer $crefoPayOmsCommandTransfer): CrefoPayApiRefundRequestTransfer
51
    {
52
        /** @var \Generated\Shared\Transfer\PaymentCrefoPayOrderItemTransfer $paymentCrefoPayOrderItemTransfer */
53
        $paymentCrefoPayOrderItemTransfer = $crefoPayOmsCommandTransfer
54
            ->getPaymentCrefoPayOrderItemCollection()
55
            ->getCrefoPayOrderItems()
56
            ->offsetGet(0);
57
58
        return (new CrefoPayApiRefundRequestTransfer())
59
            ->setMerchantID($this->config->getMerchantId())
60
            ->setStoreID($this->config->getStoreId())
61
            ->setOrderID($crefoPayOmsCommandTransfer->getPaymentCrefoPay()->getCrefoPayOrderId())
62
            ->setCaptureID($paymentCrefoPayOrderItemTransfer->getCaptureId())
63
            ->setAmount($this->createAmountTransfer($crefoPayOmsCommandTransfer))
64
            ->setRefundDescription($this->getRefundDescription($crefoPayOmsCommandTransfer));
65
    }
66
67
    /**
68
     * @param \Generated\Shared\Transfer\CrefoPayOmsCommandTransfer $crefoPayOmsCommandTransfer
69
     *
70
     * @return \Generated\Shared\Transfer\CrefoPayApiAmountTransfer
71
     */
72
    protected function createAmountTransfer(CrefoPayOmsCommandTransfer $crefoPayOmsCommandTransfer): CrefoPayApiAmountTransfer
73
    {
74
        return (new CrefoPayApiAmountTransfer())
75
            ->setAmount($crefoPayOmsCommandTransfer->getRefund()->getAmount());
76
    }
77
78
    /**
79
     * @param \Generated\Shared\Transfer\CrefoPayOmsCommandTransfer $crefoPayOmsCommandTransfer
80
     *
81
     * @return string|null
82
     */
83
    protected function getRefundDescription(CrefoPayOmsCommandTransfer $crefoPayOmsCommandTransfer): ?string
84
    {
85
        return $crefoPayOmsCommandTransfer->getRefund()->getComment() ?? $this->config->getRefundDescription();
86
    }
87
}
88