Conditions | 8 |
Paths | 5 |
Total Lines | 59 |
Code Lines | 29 |
Lines | 0 |
Ratio | 0 % |
Tests | 30 |
CRAP Score | 8 |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
17 | 4 | public function execute($request) |
|
18 | { |
||
19 | 4 | RequestNotSupportedException::assertSupports($this, $request); |
|
20 | |||
21 | 4 | $details = ArrayObject::ensureArrayObject($request->getModel()); |
|
22 | |||
23 | 4 | if (isset($details['processID']) === true && isset($details['stName']) === true) { |
|
24 | 1 | $request->markCaptured(); |
|
25 | |||
26 | 1 | return; |
|
27 | } |
||
28 | |||
29 | 4 | if (isset($details['order_id']) === true && isset($details['sn_id']) === true) { |
|
30 | 2 | if ($details['order_status'] === 'S01') { |
|
31 | 1 | $request->markCaptured(); |
|
32 | |||
33 | 1 | return; |
|
34 | } |
||
35 | |||
36 | 1 | $request->markFailed(); |
|
37 | |||
38 | 1 | return; |
|
39 | } |
||
40 | |||
41 | 3 | if (isset($details['sn_id']) === true && isset($details['order_status']) === true) { |
|
42 | $status = [ |
||
43 | // 尚未寄件或尚未收到超商總公司提供的寄件訊息 |
||
44 | 2 | 'S01' => 'markUnknown', |
|
45 | // 運往取件門市途中 |
||
46 | 2 | 'S02' => 'markUnknown', |
|
47 | // 已送達取件門市 |
||
48 | 2 | 'S03' => 'markUnknown', |
|
49 | // 已完成取貨 |
||
50 | 2 | 'S04' => 'markUnknown', |
|
51 | // 退貨 (包含:已退回物流中心 / 再寄一次給取件人 / 退回給寄件人) |
||
52 | 2 | 'S05' => 'markUnknown', |
|
53 | // 配送異常 (包含:刪單 / 門市閉店 / 貨故) |
||
54 | 2 | 'S06' => 'markUnknown', |
|
55 | // 參數傳遞內容有誤或欄位短缺 |
||
56 | 2 | 'E00' => 'markFailed', |
|
57 | // <su_id>帳號不存在 |
||
58 | 2 | 'E01' => 'markFailed', |
|
59 | // <su_id>帳號無網站串接權限 |
||
60 | 2 | 'E02' => 'markFailed', |
|
61 | // <sn_id>店到店編號有誤 |
||
62 | 2 | 'E03' => 'markFailed', |
|
63 | // <su_id>帳號與<sn_id>店到店編號無法對應 |
||
64 | 2 | 'E04' => 'markFailed', |
|
65 | // 系統錯誤 |
||
66 | 2 | 'E99' => 'markFailed', |
|
67 | 2 | ]; |
|
68 | |||
69 | 2 | call_user_func([$request, $status[$details['order_status']]]); |
|
70 | |||
71 | 2 | return; |
|
72 | } |
||
73 | |||
74 | 1 | $request->markNew(); |
|
75 | 1 | } |
|
76 | |||
87 |