Completed
Pull Request — master (#4)
by Andrey
10:46 queued 03:14
created

getSalesOrderItemsForGroup()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 4
nop 2
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Apache OSL-2
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerEco\Zed\Amazonpay\Communication\Plugin\Oms\Command;
9
10
use Generated\Shared\Transfer\AmazonpayCallTransfer;
11
use Orm\Zed\Sales\Persistence\SpySalesOrder;
1 ignored issue
show
Bug introduced by
The type Orm\Zed\Sales\Persistence\SpySalesOrder 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 Spryker\Zed\Oms\Business\Util\ReadOnlyArrayObject;
13
14
class RefundOrderCommandPlugin extends AbstractAmazonpayCommandPlugin
15
{
16
17
    /**
18
     * @var array
19
     */
20
    protected $salesOrderItemsMap = [];
21
22
    /**
23
     * @inheritdoc
24
     */
25
    public function run(array $salesOrderItems, SpySalesOrder $orderEntity, ReadOnlyArrayObject $data)
26
    {
27
        $amazonpayCallTransfers = $this->groupSalesOrderItemsByCaptureId($salesOrderItems);
28
29
        foreach ($amazonpayCallTransfers as $amazonpayCallTransfer) {
30
            $currentGroupSalesOrderItems = $this->getSalesOrderItemsForGroup($amazonpayCallTransfer, $salesOrderItems);
31
32
            $refundTransfer = $this->getFactory()
33
                ->getRefundFacade()
34
                ->calculateRefund($currentGroupSalesOrderItems, $orderEntity);
35
36
            $amazonpayCallTransfer->setRequestedAmount(
37
                $refundTransfer->getAmount()
38
            );
39
40
            $this->getFacade()->refundOrder($amazonpayCallTransfer);
0 ignored issues
show
Bug introduced by
The method refundOrder() does not exist on SprykerEco\Zed\Amazonpay...payCommunicationFactory. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

40
            $this->getFacade()->/** @scrutinizer ignore-call */ refundOrder($amazonpayCallTransfer);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
41
        }
42
43
        return [];
44
    }
45
46
    /**
47
     * @param \Generated\Shared\Transfer\AmazonpayCallTransfer $amazonpayCallTransfer
48
     * @param \Orm\Zed\Sales\Persistence\Base\SpySalesOrderItem[] $salesOrderItems
49
     *
50
     * @return \Orm\Zed\Sales\Persistence\Base\SpySalesOrderItem[]
51
     */
52
    protected function getSalesOrderItemsForGroup(AmazonpayCallTransfer $amazonpayCallTransfer, array $salesOrderItems)
53
    {
54
        if (empty($this->salesOrderItemsMap)) {
55
            $this->buildSalesOrderItemsMap($salesOrderItems);
56
        }
57
58
        $result = [];
59
60
        foreach ($amazonpayCallTransfer->getItems() as $itemTransfer) {
61
            $result[] = $this->salesOrderItemsMap[$itemTransfer->getIdSalesOrderItem()];
62
        }
63
64
        return $result;
65
    }
66
67
    /**
68
     * @param \Orm\Zed\Sales\Persistence\Base\SpySalesOrderItem[] $salesOrderItems
69
     *
70
     * @return void
71
     */
72
    protected function buildSalesOrderItemsMap(array $salesOrderItems)
73
    {
74
        foreach ($salesOrderItems as $salesOrderItem) {
75
            $this->salesOrderItemsMap[$salesOrderItem->getIdSalesOrderItem()] = $salesOrderItem;
76
        }
77
    }
78
79
}
80