Passed
Branch feature/ECO-573-per-item-proce... (fe5bf4)
by Andrey
04:56
created

RefundOrderModel   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A refundPayment() 0 12 3
A __construct() 0 5 1
1
<?php
2
3
namespace SprykerEco\Zed\Amazonpay\Business\Order;
4
5
use Orm\Zed\Amazonpay\Persistence\SpyPaymentAmazonpay;
1 ignored issue
show
Bug introduced by
The type Orm\Zed\Amazonpay\Persistence\SpyPaymentAmazonpay 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...
6
use SprykerEco\Zed\Amazonpay\Dependency\Facade\AmazonpayToRefundInterface;
7
8
class RefundOrderModel implements RefundOrderInterface
9
{
10
11
    /**
12
     * @var \SprykerEco\Zed\Amazonpay\Dependency\Facade\AmazonpayToRefundInterface
13
     */
14
    protected $refundFacade;
15
16
    /**
17
     * @param \SprykerEco\Zed\Amazonpay\Dependency\Facade\AmazonpayToRefundInterface $refundFacade
18
     */
19
    public function __construct(
20
        AmazonpayToRefundInterface $refundFacade
21
    ) {
22
23
        $this->refundFacade = $refundFacade;
24
    }
25
26
    /**
27
     * @param \Orm\Zed\Amazonpay\Persistence\SpyPaymentAmazonpay $paymentEntity
28
     *
29
     * @return void
30
     */
31
    public function refundPayment(SpyPaymentAmazonpay $paymentEntity)
32
    {
33
        /** @var \Orm\Zed\Sales\Persistence\SpySalesOrderItem[] $items */
34
        $items = [];
35
36
        foreach ($paymentEntity->getSpyPaymentAmazonpaySalesOrderItems() as $amazonpaySalesOrderItem) {
37
            $items[] = $amazonpaySalesOrderItem->getSpySalesOrderItem();
38
        }
39
40
        if (count($items) > 0) {
41
            $refundTransfer = $this->refundFacade->calculateRefund($items, $items[0]->getOrder());
42
            $this->refundFacade->saveRefund($refundTransfer);
43
        }
44
    }
45
46
}
47