isInCloseAllowedState()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 7
c 1
b 1
f 0
nc 1
nop 1
dl 0
loc 9
rs 10
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\Condition;
9
10
use Orm\Zed\Sales\Persistence\SpySalesOrderItem;
11
use Spryker\Zed\Oms\Dependency\Plugin\Condition\ConditionInterface;
12
use SprykerEco\Shared\AmazonPay\AmazonPayConfig;
13
14
class IsCloseAllowedConditionPlugin implements ConditionInterface
15
{
16
    /**
17
     * @api
18
     *
19
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrderItem $orderItem
20
     *
21
     * @return bool
22
     */
23
    public function check(SpySalesOrderItem $orderItem)
24
    {
25
        foreach ($orderItem->getOrder()->getItems() as $salesOrderItem) {
26
            if (!$this->isInCloseAllowedState($salesOrderItem->getState()->getName())) {
27
                return false;
28
            }
29
        }
30
31
        return true;
32
    }
33
34
    /**
35
     * @param string $state
36
     *
37
     * @return bool
38
     */
39
    protected function isInCloseAllowedState($state)
40
    {
41
        return in_array($state, [
42
            AmazonPayConfig::OMS_STATUS_CAPTURE_COMPLETED,
43
            AmazonPayConfig::OMS_STATUS_REFUND_COMPLETED,
44
            AmazonPayConfig::OMS_STATUS_REFUND_PENDING,
45
            AmazonPayConfig::OMS_STATUS_REFUND_DECLINED,
46
            AmazonPayConfig::OMS_STATUS_REFUND_WAITING_FOR_STATUS,
47
        ], true);
48
    }
49
}
50