| Conditions | 15 |
| Paths | 108 |
| Total Lines | 60 |
| 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 |
||
| 95 | public function generateExportFileData($gridField) |
||
| 96 | { |
||
| 97 | //reset time limit |
||
| 98 | set_time_limit(1200); |
||
| 99 | |||
| 100 | $idArray = array(); |
||
| 101 | |||
| 102 | $items = $gridField->getManipulatedList(); |
||
| 103 | |||
| 104 | foreach ($items->limit(null) as $item) { |
||
| 105 | if (!$item->hasMethod('canView') || $item->canView()) { |
||
| 106 | $idArray[$item->ID] = $item->ID; |
||
| 107 | } |
||
| 108 | } |
||
| 109 | |||
| 110 | //file data |
||
| 111 | $now = Date('d-m-Y-H-i'); |
||
| 112 | $fileName = "export-$now.csv"; |
||
| 113 | |||
| 114 | //data object variables |
||
| 115 | $orderStatusSubmissionLog = EcommerceConfig::get('OrderStatusLog', 'order_status_log_class_used_for_submitting_order'); |
||
| 116 | $fileData = ''; |
||
| 117 | $offset = 0; |
||
| 118 | $count = 50; |
||
| 119 | $orders = $this->getMyOrders($idArray, $count, $offset); |
||
| 120 | |||
| 121 | while ( |
||
| 122 | $orders->count() |
||
| 123 | ) { |
||
| 124 | $offset = $offset + $count; |
||
| 125 | foreach ($orders as $order) { |
||
| 126 | if ($order->IsSubmitted()) { |
||
| 127 | $memberIsOK = false; |
||
| 128 | if (!$order->MemberID) { |
||
| 129 | $memberIsOK = true; |
||
| 130 | } elseif (!$order->Member()) { |
||
| 131 | $memberIsOK = true; |
||
| 132 | } elseif ($member = $order->Member()) { |
||
| 133 | $memberIsOK = true; |
||
| 134 | if ($member->IsShopAdmin()) { |
||
| 135 | $memberIsOK = false; |
||
| 136 | } |
||
| 137 | } |
||
| 138 | if ($memberIsOK) { |
||
| 139 | $items = OrderItem::get()->filter(array('OrderID' => $order->ID)); |
||
| 140 | if ($items && $items->count()) { |
||
| 141 | $fileData .= $this->generateExportFileDataDetails($order->getOrderEmail(), $order->SubmissionLog()->Created, $items); |
||
| 142 | } |
||
| 143 | } |
||
| 144 | } |
||
| 145 | } |
||
| 146 | unset($orders); |
||
| 147 | $orders = $this->getMyOrders($idArray, $count, $offset); |
||
| 148 | } |
||
| 149 | if ($fileData) { |
||
| 150 | return $fileData; |
||
| 151 | } else { |
||
| 152 | return null; |
||
| 153 | } |
||
| 154 | } |
||
| 155 | |||
| 216 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.