| Conditions | 18 |
| Paths | 199 |
| Total Lines | 94 |
| Lines | 10 |
| Ratio | 10.64 % |
| 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 |
||
| 179 | public function doSave($data, $form, $request) |
||
| 180 | { |
||
| 181 | $data = Convert::raw2sql($data); |
||
| 182 | $member = Member::currentUser(); |
||
| 183 | if (!$member) { |
||
| 184 | $form->sessionMessage('Could not find customer details.', 'bad'); |
||
| 185 | $this->controller->redirectBack(); |
||
| 186 | |||
| 187 | return false; |
||
| 188 | } |
||
| 189 | if ($member->IsShopAdmin()) { |
||
| 190 | $form->sessionMessage('Repeat orders can not be created by Shop Administrators. Only customers can create repeat orders.', 'bad'); |
||
| 191 | $this->controller->redirectBack(); |
||
| 192 | |||
| 193 | return false; |
||
| 194 | } |
||
| 195 | if (isset($data['OrderID'])) { |
||
| 196 | $orderID = intval($data['OrderID']); |
||
| 197 | if($orderID) { |
||
| 198 | $order = DataObject::get_one('Order', 'Order.ID = \''.$orderID.'\' AND MemberID = \''.$member->ID.'\''); |
||
| 199 | if ($order) { |
||
| 200 | $repeatOrder = RepeatOrder::create_repeat_order_from_order($order); |
||
| 201 | if($repeatOrder) { |
||
| 202 | $repeatOrder->OriginatingOrderID = $order->ID; |
||
| 203 | $repeatOrder->write(); |
||
| 204 | } else { |
||
| 205 | $form->sessionMessage('Sorry, an error occured - we could not create your subscribtion order. Please try again.', 'bad'); |
||
| 206 | $this->controller->redirectBack(); |
||
| 207 | |||
| 208 | return false; |
||
| 209 | } |
||
| 210 | } else { |
||
| 211 | $form->sessionMessage('Could not find originating order.', 'bad'); |
||
| 212 | $this->controller->redirectBack(); |
||
| 213 | |||
| 214 | return false; |
||
| 215 | } |
||
| 216 | } |
||
| 217 | } else { |
||
| 218 | $repeatOrderID = intval($data['RepeatOrderID']); |
||
| 219 | $repeatOrder = DataObject::get_one('RepeatOrder', 'RepeatOrder.ID = \''.$repeatOrderID.'\' AND MemberID = \''.$member->ID.'\''); |
||
| 220 | } |
||
| 221 | if ($repeatOrder) { |
||
| 222 | if ($repeatOrderItems = $repeatOrder->OrderItems()) { |
||
| 223 | foreach ($repeatOrderItems as $repeatOrderItem) { |
||
| 224 | $repeatOrderItem->ProductID = $data["Product"]["ID"][$repeatOrderItem->ProductID]; |
||
| 225 | $repeatOrderItem->Quantity = $data["Product"]["Quantity"][$repeatOrderItem->ProductID]; |
||
| 226 | $altCount = Config::inst()->get('RepeatOrderForm', 'number_of_product_alternatives'); |
||
| 227 | for ($i = 1; $i <= $altCount; $i++) { |
||
| 228 | $alternativeField = "Alternative".$i."ID"; |
||
| 229 | $repeatOrderItem->$alternativeField = $data["Product"][$alternativeField][$repeatOrderItem->ProductID]; |
||
| 230 | } |
||
| 231 | $repeatOrderItem->write(); |
||
| 232 | } |
||
| 233 | } |
||
| 234 | $params = []; |
||
| 235 | View Code Duplication | if (isset($data['Start']) && strtotime($data['Start']) > strtotime(Date("Y-m-d"))) { |
|
| 236 | $params['Start'] = $data['Start']; |
||
| 237 | } else { |
||
| 238 | $params["Start"] = Date("Y-m-d"); |
||
| 239 | } |
||
| 240 | View Code Duplication | if (isset($data['End']) && strtotime($data['End']) > strtotime($params["Start"])) { |
|
| 241 | $params['End'] = $data['End']; |
||
| 242 | } else { |
||
| 243 | $params["End"] = Date("Y-m-d", strtotime("+1 year")); |
||
| 244 | } |
||
| 245 | if (isset($data['Period'])) { |
||
| 246 | $params['Period'] = $data['Period']; |
||
| 247 | } else { |
||
| 248 | $data['Period'] = RepeatOrder::default_period_key(); |
||
| 249 | } |
||
| 250 | if (isset($data['PaymentMethod'])) { |
||
| 251 | $params['PaymentMethod'] = $data['PaymentMethod']; |
||
| 252 | } else { |
||
| 253 | $data['PaymentMethod'] = RepeatOrder::default_payment_method_key(); |
||
| 254 | } |
||
| 255 | if (isset($data['Notes'])) { |
||
| 256 | $params['Notes'] = $data['Notes']; |
||
| 257 | } |
||
| 258 | $repeatOrder->update($params); |
||
| 259 | $repeatOrder->Status = 'Pending'; |
||
| 260 | $repeatOrder->write(); |
||
| 261 | } else { |
||
| 262 | $form->sessionMessage('Could not find repeat order.', 'bad'); |
||
| 263 | $this->controller->redirectBack(); |
||
| 264 | |||
| 265 | return false; |
||
| 266 | } |
||
| 267 | $this->controller->redirect( |
||
| 268 | RepeatOrdersPage::get_repeat_order_link('view', $repeatOrder->ID) |
||
| 269 | ); |
||
| 270 | |||
| 271 | return true; |
||
| 272 | } |
||
| 273 | |||
| 291 |
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.