AbstractByOrderItemConditionPlugin   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 55
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A check() 0 9 2
A isMatchingStatus() 0 9 2
A getPaymentAmazonpayBySalesOrderItem() 0 9 2
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
13
abstract class AbstractByOrderItemConditionPlugin implements ConditionInterface
14
{
15
    /**
16
     * @return string|array
17
     */
18
    abstract protected function getPaymentStatus();
19
20
    /**
21
     * @api
22
     *
23
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrderItem $orderItem
24
     *
25
     * @return bool
26
     */
27
    public function check(SpySalesOrderItem $orderItem)
28
    {
29
        $payment = $this->getPaymentAmazonpayBySalesOrderItem($orderItem);
30
31
        if ($payment === null) {
32
            return true;
33
        }
34
35
        return $this->isMatchingStatus($payment->getStatus());
36
    }
37
38
    /**
39
     * @param string $status
40
     *
41
     * @return bool
42
     */
43
    protected function isMatchingStatus($status)
44
    {
45
        $expectedStatus = $this->getPaymentStatus();
46
47
        if (is_array($expectedStatus)) {
48
            return in_array($status, $expectedStatus, true);
49
        }
50
51
        return $status === $expectedStatus;
52
    }
53
54
    /**
55
     * @param \Orm\Zed\Sales\Persistence\SpySalesOrderItem $orderItem
56
     *
57
     * @return \Orm\Zed\AmazonPay\Persistence\SpyPaymentAmazonpay|null
58
     */
59
    protected function getPaymentAmazonpayBySalesOrderItem(SpySalesOrderItem $orderItem)
60
    {
61
        $lastPayment = $orderItem->getSpyPaymentAmazonpaySalesOrderItems()->getLast();
62
63
        if (!$lastPayment) {
64
            return null;
65
        }
66
67
        return $lastPayment->getSpyPaymentAmazonpay();
68
    }
69
}
70