| Conditions | 6 |
| Paths | 10 |
| Total Lines | 59 |
| Code Lines | 41 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 2 | Features | 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 |
||
| 111 | public function checkExport($gridField, $request = null) { |
||
| 112 | $id = $request->param('ID'); |
||
| 113 | $job = QueuedJobDescriptor::get()->filter('Signature', $id)->first(); |
||
| 114 | |||
| 115 | $controller = $gridField->getForm()->getController(); |
||
| 116 | |||
| 117 | $breadcrumbs = $controller->Breadcrumbs(false); |
||
| 118 | $breadcrumbs->push(new ArrayData(array( |
||
| 119 | 'Title' => _t('TableListField.CSVEXPORT', 'Export to CSV'), |
||
| 120 | 'Link' => false |
||
| 121 | ))); |
||
| 122 | |||
| 123 | $parents = $controller->Breadcrumbs(false)->items; |
||
| 124 | $backlink = array_pop($parents)->Link; |
||
| 125 | |||
| 126 | $data = new ArrayData(array( |
||
| 127 | 'ID' => $id, |
||
| 128 | 'Link' => Controller::join_links($gridField->Link(), 'export', $job->Signature), |
||
| 129 | 'Backlink' => $backlink, |
||
| 130 | 'Breadcrumbs' => $breadcrumbs, |
||
| 131 | 'GridName' => $gridField->getname() |
||
| 132 | )); |
||
| 133 | |||
| 134 | if ($job->JobStatus == QueuedJob::STATUS_COMPLETE) { |
||
| 135 | if (file_exists($this->getExportPath($id))) { |
||
| 136 | $data->DownloadLink = $gridField->Link('/export_download/' . $job->Signature); |
||
| 137 | } |
||
| 138 | else { |
||
| 139 | $data->ErrorMessage = _t( |
||
| 140 | 'GridFieldQueuedExportButton.ERROR_REMOVED', |
||
| 141 | 'This export has already been downloaded. For security reasons each export can only be downloaded once.' |
||
| 142 | ); |
||
| 143 | } |
||
| 144 | } else if ($job->JobStatus == QueuedJob::STATUS_BROKEN) { |
||
| 145 | $data->ErrorMessage = _t( |
||
| 146 | 'GridFieldQueuedExportButton.ERROR_GENERAL', |
||
| 147 | 'Sorry, but there was an error exporting the CSV' |
||
| 148 | ); |
||
| 149 | } else if ($job->JobStatus == QueuedJob::STATUS_CANCELLED) { |
||
| 150 | $data->ErrorMessage = _t( |
||
| 151 | 'GridFieldQueuedExportButton.CANCELLED', |
||
| 152 | 'This export job was cancelled' |
||
| 153 | ); |
||
| 154 | } else { |
||
| 155 | $data->Count = $job->StepsProcessed; |
||
| 156 | $data->Total = $job->TotalSteps; |
||
| 157 | } |
||
| 158 | |||
| 159 | Requirements::javascript('gridfieldqueuedexport/client/GridFieldQueuedExportButton.js'); |
||
| 160 | Requirements::css('gridfieldqueuedexport/client/GridFieldQueuedExportButton.css'); |
||
| 161 | |||
| 162 | $return = $data->renderWith('GridFieldQueuedExportButton'); |
||
| 163 | |||
| 164 | if ($request->isAjax()) { |
||
| 165 | return $return; |
||
| 166 | } else { |
||
| 167 | return $controller->customise(array('Content' => $return)); |
||
| 168 | } |
||
| 169 | } |
||
| 170 | |||
| 251 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.