Completed
Pull Request — master (#10)
by
unknown
05:04
created

StatusLogisticsAction::execute()   C

Complexity

Conditions 15
Paths 12

Size

Total Lines 76
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 240

Importance

Changes 0
Metric Value
dl 0
loc 76
ccs 0
cts 38
cp 0
rs 5.257
c 0
b 0
f 0
cc 15
eloc 37
nc 12
nop 1
crap 240

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace PayumTW\Ecpay\Action;
4
5
use Payum\Core\Action\ActionInterface;
6
use Payum\Core\Bridge\Spl\ArrayObject;
7
use Payum\Core\Request\GetStatusInterface;
8
use Payum\Core\Exception\RequestNotSupportedException;
9
10
class StatusLogisticsAction implements ActionInterface
11
{
12
    /**
13
     * {@inheritdoc}
14
     *
15
     * @param GetStatusInterface $request
16
     */
17
    public function execute($request)
18
    {
19
        RequestNotSupportedException::assertSupports($this, $request);
20
21
        $details = ArrayObject::ensureArrayObject($request->getModel());
22
23
        if (isset($details['ErrorMessage']) === true) {
24
            $request->markFailed();
25
26
            return;
27
        }
28
29
        if (isset($details['ResCode']) === true) {
30
            if ($details['ResCode'] === '0') {
31
                $request->markFailed();
32
33
                return;
34
            }
35
36
            $request->markCaptured();
37
38
            return;
39
        }
40
41
        if (isset($details['RtnCode']) === true) {
42
            if ($details['RtnCode'] === '0') {
43
                $request->markFailed();
44
45
                return;
46
            }
47
48
            if ($details['RtnCode'] === '1') {
49
                if (isset($details['RtnMerchantTradeNo']) === true) {
50
                    $request->markRefunded();
51
52
                    return;
53
                }
54
                // 取消訂單(統一超商C2C).
55
                if (isset($details['CVSPaymentNo']) === true && isset($details['MerchantTradeDate']) === false) {
56
                    $request->markCanceled();
57
58
                    return;
59
                }
60
61
                // 宅配逆物流訂單產生
62
                if (isset($details['AllPayLogisticsID']) === true && isset($details['MerchantTradeDate']) === false) {
63
                    $request->markRefunded();
64
65
                    return;
66
                }
67
68
                $request->markCaptured();
69
70
                return;
71
            }
72
73
            $request->markUnknown();
74
75
            return;
76
        }
77
78
        // 超商取貨逆物流訂單(全家超商B2C).
79
        if (isset($details['RtnMerchantTradeNo']) === true && isset($details['RtnOrderNo']) === true) {
80
            $request->markRefunded();
81
82
            return;
83
        }
84
85
        if (isset($details['CVSStoreID']) === true) {
86
            $request->markCaptured();
87
88
            return;
89
        }
90
91
        $request->markNew();
92
    }
93
94
    /**
95
     * {@inheritdoc}
96
     */
97
    public function supports($request)
98
    {
99
        return
100
            $request instanceof GetStatusInterface &&
101
            $request->getModel() instanceof \ArrayAccess;
102
    }
103
}
104