| Conditions | 16 |
| Paths | 133 |
| Total Lines | 82 |
| Lines | 10 |
| Ratio | 12.2 % |
| 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 |
||
| 175 | public function doSave($data, $form, $request) |
||
| 176 | { |
||
| 177 | $data = Convert::raw2sql($data); |
||
| 178 | $member = Member::currentUser(); |
||
| 179 | if (!$member) { |
||
| 180 | $form->sessionMessage('Could not find customer details.', 'bad'); |
||
| 181 | $this->controller->redirectBack(); |
||
| 182 | |||
| 183 | return false; |
||
| 184 | } |
||
| 185 | if ($member->IsShopAdmin()) { |
||
| 186 | $form->sessionMessage('Repeat orders can not be created by Shop Administrators. Only customers can create repeat orders.', 'bad'); |
||
| 187 | $this->controller->redirectBack(); |
||
| 188 | |||
| 189 | return false; |
||
| 190 | } |
||
| 191 | if (isset($data['OrderID'])) { |
||
| 192 | $order = DataObject::get_one('Order', 'Order.ID = \''.$data['OrderID'].'\' AND MemberID = \''.$member->ID.'\''); |
||
| 193 | if ($order) { |
||
| 194 | $repeatOrder = RepeatOrder::create_repeat_order_from_order($order); |
||
| 195 | } else { |
||
| 196 | $form->sessionMessage('Could not find originating order.', 'bad'); |
||
| 197 | $this->controller->redirectBack(); |
||
| 198 | |||
| 199 | return false; |
||
| 200 | } |
||
| 201 | } else { |
||
| 202 | $repeatOrderID = intval($data['RepeatOrderID']); |
||
| 203 | $repeatOrder = DataObject::get_one('RepeatOrder', 'RepeatOrder.ID = \''.$repeatOrderID.'\' AND MemberID = \''.$member->ID.'\''); |
||
| 204 | } |
||
| 205 | if ($repeatOrder) { |
||
| 206 | if ($repeatOrderItems = $repeatOrder->OrderItems()) { |
||
| 207 | foreach ($repeatOrderItems as $repeatOrderItem) { |
||
| 208 | $repeatOrderItem->ProductID = $data["Product"]["ID"][$repeatOrderItem->ProductID]; |
||
| 209 | $repeatOrderItem->Quantity = $data["Product"]["Quantity"][$repeatOrderItem->ProductID]; |
||
| 210 | $altCount = Config::inst()->get('RepeatOrderForm', 'number_of_product_alternatives'); |
||
| 211 | for ($i = 1; $i <= $altCount; $i++) { |
||
| 212 | $alternativeField = "Alternative".$i."ID"; |
||
| 213 | $repeatOrderItem->$alternativeField = $data["Product"][$alternativeField][$repeatOrderItem->ProductID]; |
||
| 214 | } |
||
| 215 | $repeatOrderItem->write(); |
||
| 216 | } |
||
| 217 | } |
||
| 218 | $params = []; |
||
| 219 | View Code Duplication | if (isset($data['Start']) && strtotime($data['Start']) > strtotime(Date("Y-m-d"))) { |
|
| 220 | $params['Start'] = $data['Start']; |
||
| 221 | } else { |
||
| 222 | $params["Start"] = Date("Y-m-d"); |
||
| 223 | } |
||
| 224 | View Code Duplication | if (isset($data['End']) && strtotime($data['End']) > strtotime($params["Start"])) { |
|
| 225 | $params['End'] = $data['End']; |
||
| 226 | } else { |
||
| 227 | $params["End"] = Date("Y-m-d", strtotime("+1 year")); |
||
| 228 | } |
||
| 229 | if (isset($data['Period'])) { |
||
| 230 | $params['Period'] = $data['Period']; |
||
| 231 | } else { |
||
| 232 | $data['Period'] = RepeatOrder::default_period_key(); |
||
| 233 | } |
||
| 234 | if (isset($data['PaymentMethod'])) { |
||
| 235 | $params['PaymentMethod'] = $data['PaymentMethod']; |
||
| 236 | } else { |
||
| 237 | $data['PaymentMethod'] = RepeatOrder::default_payment_method_key(); |
||
| 238 | } |
||
| 239 | if (isset($data['Notes'])) { |
||
| 240 | $params['Notes'] = $data['Notes']; |
||
| 241 | } |
||
| 242 | $repeatOrder->update($params); |
||
| 243 | $repeatOrder->Status = 'Pending'; |
||
| 244 | $repeatOrder->write(); |
||
| 245 | } else { |
||
| 246 | $form->sessionMessage('Could not find repeat order.', 'bad'); |
||
| 247 | $this->controller->redirectBack(); |
||
| 248 | |||
| 249 | return false; |
||
| 250 | } |
||
| 251 | $this->controller->redirect( |
||
| 252 | RepeatOrdersPage::get_repeat_order_link('view', $repeatOrder->ID) |
||
| 253 | ); |
||
| 254 | |||
| 255 | return true; |
||
| 256 | } |
||
| 257 | |||
| 275 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.