Conditions | 17 |
Paths | 7 |
Total Lines | 42 |
Lines | 0 |
Ratio | 0 % |
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 |
||
23 | public function getTransactionStatus(): string |
||
24 | { |
||
25 | // If the user cancelled in the terminal window, then we need to detect that. |
||
26 | if ($this->hasError()) { |
||
27 | $error = $this->getError(); |
||
28 | if ( |
||
29 | !empty($error['operation']) && $error['operation'] === 'Terminal' && |
||
30 | !empty($error['responseCode']) && $error['responseCode'] === '17' && |
||
31 | !empty($error['responseSource']) && ($error['responseSource'] === 'Terminal' || $error['responseSource'] === '05') && |
||
32 | !empty($error['responseText']) && $error['responseText'] === 'Cancelled by customer.' |
||
33 | ) { |
||
34 | return QueryInterface::STATUS_CANCELLED; |
||
35 | } |
||
36 | |||
37 | return QueryInterface::STATUS_FAILED; |
||
38 | } |
||
39 | |||
40 | $summary = $this->getSummary(); |
||
41 | |||
42 | // If the cancelled flag is set, then it can no longer be considered to be authed, captured or credited. |
||
43 | if ($summary['cancelled']) { |
||
44 | return QueryInterface::STATUS_CANCELLED; |
||
45 | } |
||
46 | |||
47 | // If there's an amount present in the amountCredited field, it's because it's not a request for payment. |
||
48 | if ($summary['amountCredited']) { |
||
49 | return QueryInterface::STATUS_CREDITED; |
||
50 | } |
||
51 | |||
52 | // If it's not cancelled, not credited, but is authed and not captured, then it must just be authed. |
||
53 | if ($summary['authorized'] && !$summary['amountCaptured']) { |
||
54 | return QueryInterface::STATUS_AUTHORIZED; |
||
55 | } |
||
56 | |||
57 | // If it's not cancelled, not credited, not authed, and not captured, then it's either pending, (Netaxept's |
||
58 | // 'registered' state) or rejected. |
||
59 | if (!$summary['authorized'] && !$summary['amountCaptured']) { |
||
60 | return QueryInterface::STATUS_PENDING; |
||
61 | } |
||
62 | |||
63 | // The only other option is that it's been captured. |
||
64 | return QueryInterface::STATUS_CAPTURED; |
||
65 | } |
||
175 |