RefundManager::getAmount()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 3
nc 2
nop 1
1
<?php
2
3
/**
4
 * MIT License
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerEco\Zed\Computop\Business\Oms\Command\Manager;
9
10
use Generated\Shared\Transfer\OrderTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\OrderTransfer 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
12
class RefundManager extends AbstractManager
13
{
14
    /**
15
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
16
     *
17
     * @return int
18
     */
19
    public function getAmount(OrderTransfer $orderTransfer)
20
    {
21
        if ($this->config->isRefundShipmentPriceEnabled() && $this->isShipmentRefundNeeded($orderTransfer)) {
22
            return $orderTransfer->getTotals()->getRefundTotal();
23
        }
24
25
        return $orderTransfer->getTotals()->getSubtotal() - $orderTransfer->getTotals()->getDiscountTotal();
26
    }
27
28
    /**
29
     * Check is last refund
30
     *
31
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
32
     *
33
     * @return bool
34
     */
35
    protected function isShipmentRefundNeeded(OrderTransfer $orderTransfer)
36
    {
37
        $itemsBeforeRefundState = count($this->getItemsBeforeRefundState($orderTransfer));
38
39
        $itemsToRefundCount = count($orderTransfer->getItems());
40
41
        return ($itemsBeforeRefundState - $itemsToRefundCount) === 0;
42
    }
43
44
    /**
45
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
46
     *
47
     * @return array
48
     */
49
    protected function getItemsBeforeRefundState(OrderTransfer $orderTransfer)
50
    {
51
        return $this
52
            ->queryContainer
53
            ->getSpySalesOrderItemsById($orderTransfer->getIdSalesOrder())
54
            ->useStateQuery()
55
            ->filterByName_In(
56
                (array)$this->config->getBeforeRefundStatuses()
57
            )
58
            ->endUse()
59
            ->find();
60
    }
61
}
62