IsCloseAllowedConditionPlugin   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 12
c 1
b 1
f 0
dl 0
loc 34
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isInCloseAllowedState() 0 9 1
A check() 0 9 3
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