| Conditions | 13 |
| Paths | 65 |
| Total Lines | 39 |
| 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 |
||
| 87 | public function addOrderStepFields(FieldList $fields, Order $order) |
||
| 88 | { |
||
| 89 | $fields = parent::addOrderStepFields($fields, $order); |
||
| 90 | if (!$order->IsSubmitted()) { |
||
| 91 | //LINE BELOW IS NOT REQUIRED |
||
| 92 | $header = _t('OrderStep.SUBMITORDER', 'Submit Order'); |
||
| 93 | $label = _t('OrderStep.SUBMITNOW', 'Submit Now'); |
||
| 94 | $msg = _t('OrderStep.MUSTDOSUBMITRECORD', '<p>Tick the box below to submit this order.</p>'); |
||
| 95 | $problems = array(); |
||
| 96 | if (!$order->getTotalItems()) { |
||
| 97 | $problems[] = 'There are no --- Order Items (products) --- associated with this order.'; |
||
| 98 | } |
||
| 99 | if (!$order->MemberID) { |
||
| 100 | $problems[] = 'There is no --- Customer --- associated with this order.'; |
||
| 101 | } |
||
| 102 | if (!$order->BillingAddressID) { |
||
| 103 | $problems[] = 'There is no --- Billing Address --- associated with this order.'; |
||
| 104 | } elseif ($billingAddress = $order->BillingAddress()) { |
||
| 105 | $requiredBillingFields = $billingAddress->getRequiredFields(); |
||
| 106 | if ($requiredBillingFields && is_array($requiredBillingFields) && count($requiredBillingFields)) { |
||
| 107 | foreach ($requiredBillingFields as $requiredBillingField) { |
||
| 108 | if (!$billingAddress->$requiredBillingField) { |
||
| 109 | $problems[] = "There is no --- $requiredBillingField --- recorded in the billing address."; |
||
| 110 | } |
||
| 111 | } |
||
| 112 | } |
||
| 113 | } |
||
| 114 | if (count($problems)) { |
||
| 115 | $msg = '<p>You can not submit this order because:</p> <ul><li>'.implode('</li><li>', $problems).'</li></ul>'; |
||
| 116 | } |
||
| 117 | $fields->addFieldToTab('Root.Next', new HeaderField('CreateSubmitRecordHeader', $header, 3), 'ActionNextStepManually'); |
||
| 118 | $fields->addFieldToTab('Root.Next', new LiteralField('CreateSubmitRecordMessage', $msg), 'ActionNextStepManually'); |
||
| 119 | if (!$problems) { |
||
| 120 | $fields->addFieldToTab('Root.Next', new CheckboxField('SubmitOrderViaCMS', $label), 'ActionNextStepManually'); |
||
| 121 | } |
||
| 122 | } |
||
| 123 | |||
| 124 | return $fields; |
||
| 125 | } |
||
| 126 | |||
| 137 |