| Conditions | 12 |
| Paths | 13 |
| Total Lines | 64 |
| Code Lines | 38 |
| 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 |
||
| 68 | public function doStep(Order $order) |
||
| 69 | { |
||
| 70 | //if the order has been paid then do not worry about it at all! |
||
| 71 | if ($order->IsPaid()) { |
||
| 72 | return true; |
||
| 73 | } |
||
| 74 | //if the order has been pending then do not do the step |
||
| 75 | elseif($order->PaymentIsPending()){ |
||
| 76 | return false; |
||
| 77 | } |
||
| 78 | //do we send at all? |
||
| 79 | elseif ($this->SendPaymentCheckEmail) { |
||
| 80 | // too late to send |
||
| 81 | if ($this->isExpiredPaymentCheckStep($order)) { |
||
| 82 | //cancel order .... |
||
| 83 | if ($this->Config()->get("verbose")) { |
||
| 84 | DB::alteration_message(" - Time to send payment reminder is expired ... archive email"); |
||
| 85 | } |
||
| 86 | // cancel as the member placing the order |
||
| 87 | $member = $order->CreateOrReturnExistingMember(); |
||
| 88 | if (! $member) { |
||
| 89 | $member = EcommerceRole::get_default_shop_admin_user(); |
||
| 90 | } |
||
| 91 | $order->Cancel( |
||
| 92 | $member, |
||
| 93 | _t('OrderStep.CANCELLED_DUE_TO_NON_PAYMENT', 'Cancelled due to non-payment') |
||
| 94 | ); |
||
| 95 | |||
| 96 | return true; |
||
| 97 | } |
||
| 98 | //is now the right time to send? |
||
| 99 | elseif ($this->isReadyToGo($order)) { |
||
| 100 | $subject = $this->EmailSubject; |
||
| 101 | $message = $this->CustomerMessage; |
||
| 102 | if ($this->hasBeenSent($order, false)) { |
||
| 103 | if ($this->Config()->get("verbose")) { |
||
| 104 | DB::alteration_message(" - already sent!"); |
||
| 105 | } |
||
| 106 | |||
| 107 | return true; //do nothing |
||
| 108 | } else { |
||
| 109 | if ($this->Config()->get("verbose")) { |
||
| 110 | DB::alteration_message(" - Sending it now!"); |
||
| 111 | } |
||
| 112 | return $order->sendEmail( |
||
| 113 | $this->getEmailClassName(), |
||
| 114 | $subject, |
||
| 115 | $message, |
||
| 116 | $resend = false, |
||
| 117 | $adminOnlyOrToEmail = false |
||
| 118 | ); |
||
| 119 | } |
||
| 120 | } |
||
| 121 | //wait until later.... |
||
| 122 | else { |
||
| 123 | if ($this->Config()->get("verbose")) { |
||
| 124 | DB::alteration_message(" - We need to wait until minimum number of days."); |
||
| 125 | } |
||
| 126 | return false; |
||
| 127 | } |
||
| 128 | } else { |
||
| 129 | return true; |
||
| 130 | } |
||
| 131 | } |
||
| 132 | |||
| 243 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.