| Conditions | 11 |
| Paths | 16 |
| Total Lines | 34 |
| Code Lines | 18 |
| 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 |
||
| 70 | private function getTargetTransition(OrderInterface $order) |
||
| 71 | { |
||
| 72 | $refundedPaymentTotal = 0; |
||
| 73 | $refundedPayments = $this->getPaymentsWithState($order, PaymentInterface::STATE_REFUNDED); |
||
| 74 | |||
| 75 | foreach ($refundedPayments as $payment) { |
||
| 76 | $refundedPaymentTotal += $payment->getAmount(); |
||
| 77 | } |
||
| 78 | |||
| 79 | if (0 < $refundedPayments->count() && $refundedPaymentTotal >= $order->getTotal()) { |
||
|
|
|||
| 80 | return OrderPaymentTransitions::TRANSITION_REFUND; |
||
| 81 | } |
||
| 82 | |||
| 83 | if ($refundedPaymentTotal < $order->getTotal() && 0 < $refundedPaymentTotal) { |
||
| 84 | return OrderPaymentTransitions::TRANSITION_PARTIALLY_REFUND; |
||
| 85 | } |
||
| 86 | |||
| 87 | $completedPaymentTotal = 0; |
||
| 88 | $completedPayments = $this->getPaymentsWithState($order, PaymentInterface::STATE_COMPLETED); |
||
| 89 | |||
| 90 | foreach ($completedPayments as $payment) { |
||
| 91 | $completedPaymentTotal += $payment->getAmount(); |
||
| 92 | } |
||
| 93 | |||
| 94 | if (0 < $completedPayments->count() && $completedPaymentTotal >= $order->getTotal()) { |
||
| 95 | return OrderPaymentTransitions::TRANSITION_PAY; |
||
| 96 | } |
||
| 97 | |||
| 98 | if ($completedPaymentTotal < $order->getTotal() && 0 < $completedPaymentTotal) { |
||
| 99 | return OrderPaymentTransitions::TRANSITION_PARTIALLY_PAY; |
||
| 100 | } |
||
| 101 | |||
| 102 | return null; |
||
| 103 | } |
||
| 104 | |||
| 118 |
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.