| Conditions | 13 |
| Paths | 36 |
| Total Lines | 54 |
| 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 |
||
| 17 | public function run($request) |
||
| 18 | { |
||
| 19 | //reset time limit |
||
| 20 | set_time_limit(1200); |
||
| 21 | |||
| 22 | //file data |
||
| 23 | $now = Date('d-m-Y-H-i'); |
||
| 24 | $fileName = "export-$now.csv"; |
||
| 25 | |||
| 26 | //data object variables |
||
| 27 | $orderStatusSubmissionLog = EcommerceConfig::get('OrderStatusLog', 'order_status_log_class_used_for_submitting_order'); |
||
| 28 | $fileData = ''; |
||
| 29 | $offset = 0; |
||
| 30 | $count = 50; |
||
| 31 | |||
| 32 | while ( |
||
| 33 | $orders = Order::get() |
||
|
|
|||
| 34 | ->sort('"Order"."ID" ASC') |
||
| 35 | ->innerJoin('OrderStatusLog', '"Order"."ID" = "OrderStatusLog"."OrderID"') |
||
| 36 | ->innerJoin($orderStatusSubmissionLog, "\"$orderStatusSubmissionLog\".\"ID\" = \"OrderStatusLog\".\"ID\"") |
||
| 37 | ->leftJoin('Member', '"Member"."ID" = "Order"."MemberID"') |
||
| 38 | ->limit($count, $offset) && |
||
| 39 | $ordersCount = $orders->count() |
||
| 40 | ) { |
||
| 41 | $offset = $offset + $count; |
||
| 42 | foreach ($orders as $order) { |
||
| 43 | if ($order->IsSubmitted()) { |
||
| 44 | $memberIsOK = false; |
||
| 45 | if (!$order->MemberID) { |
||
| 46 | $memberIsOK = true; |
||
| 47 | } elseif (!$order->Member()) { |
||
| 48 | $memberIsOK = true; |
||
| 49 | } elseif ($member = $order->Member()) { |
||
| 50 | $memberIsOK = true; |
||
| 51 | if ($member->IsShopAssistant()) { |
||
| 52 | $memberIsOK = false; |
||
| 53 | } |
||
| 54 | } |
||
| 55 | if ($memberIsOK) { |
||
| 56 | $items = OrderItem::get()->filter(array('OrderID' => $order->ID)); |
||
| 57 | if ($items && $items->count()) { |
||
| 58 | $fileData .= $this->generateExportFileData($order->getOrderEmail(), $order->SubmissionLog()->Created, $items); |
||
| 59 | } |
||
| 60 | } |
||
| 61 | } |
||
| 62 | } |
||
| 63 | unset($orders); |
||
| 64 | } |
||
| 65 | if ($fileData) { |
||
| 66 | SS_HTTPRequest::send_file($fileData, $fileName, 'text/csv'); |
||
| 67 | } else { |
||
| 68 | user_error('No records found', E_USER_ERROR); |
||
| 69 | } |
||
| 70 | } |
||
| 71 | |||
| 112 |