| Conditions | 12 |
| Paths | 20 |
| Total Lines | 40 |
| 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 |
||
| 57 | private function getTargetTransition(SubscriptionInterface $subscription) |
||
| 58 | { |
||
| 59 | $refundedPaymentTotal = 0; |
||
| 60 | $refundedPayments = $this->getPaymentsWithState($subscription, PaymentInterface::STATE_REFUNDED); |
||
| 61 | |||
| 62 | foreach ($refundedPayments as $payment) { |
||
| 63 | $refundedPaymentTotal += $payment->getAmount(); |
||
| 64 | } |
||
| 65 | |||
| 66 | if (0 < $refundedPayments->count() && $refundedPaymentTotal >= $subscription->getTotal()) { |
||
| 67 | return SubscriptionPaymentTransitions::TRANSITION_REFUND; |
||
| 68 | } |
||
| 69 | |||
| 70 | if ($refundedPaymentTotal < $subscription->getTotal() && 0 < $refundedPaymentTotal) { |
||
| 71 | return SubscriptionPaymentTransitions::TRANSITION_PARTIALLY_REFUND; |
||
| 72 | } |
||
| 73 | |||
| 74 | $completedPaymentTotal = 0; |
||
| 75 | $completedPayments = $this->getPaymentsWithState($subscription, PaymentInterface::STATE_COMPLETED); |
||
| 76 | |||
| 77 | foreach ($completedPayments as $payment) { |
||
| 78 | $completedPaymentTotal += $payment->getAmount(); |
||
| 79 | } |
||
| 80 | |||
| 81 | if (0 < $completedPayments->count() && $completedPaymentTotal >= $subscription->getTotal()) { |
||
| 82 | return SubscriptionPaymentTransitions::TRANSITION_PAY; |
||
| 83 | } |
||
| 84 | |||
| 85 | if ($completedPaymentTotal < $subscription->getTotal() && 0 < $completedPaymentTotal) { |
||
| 86 | return SubscriptionPaymentTransitions::TRANSITION_PARTIALLY_PAY; |
||
| 87 | } |
||
| 88 | |||
| 89 | $cancelledPayments = $this->getPaymentsWithState($subscription, PaymentInterface::STATE_CANCELLED); |
||
| 90 | |||
| 91 | if (0 < $cancelledPayments->count()) { |
||
| 92 | return SubscriptionPaymentTransitions::TRANSITION_CANCEL; |
||
| 93 | } |
||
| 94 | |||
| 95 | return null; |
||
| 96 | } |
||
| 97 | |||
| 111 |