Conditions | 3 |
Paths | 4 |
Total Lines | 97 |
Code Lines | 66 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | 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 |
||
192 | public function getCMSFields() |
||
193 | { |
||
194 | $fields = parent::getCMSFields(); |
||
195 | |||
196 | $remove = [ |
||
197 | 'Categories', |
||
198 | 'CareCleaningDocs', |
||
199 | 'OperationManuals', |
||
200 | 'SpecSheets', |
||
201 | 'Warranties', |
||
202 | 'DisabledBlocks', |
||
203 | 'Slides', |
||
204 | ]; |
||
205 | |||
206 | if (!$this->ID) { |
||
207 | $remove[] = 'Blocks'; |
||
208 | } |
||
209 | |||
210 | $fields->removeByName($remove); |
||
211 | |||
212 | $fields->insertBefore( |
||
213 | $fields->dataFieldByName('SKU'), |
||
214 | 'Content' |
||
215 | ); |
||
216 | |||
217 | $fields->addFieldsToTab('Root.Info', array( |
||
218 | TextField::create('Dimensions'), |
||
219 | HTMLEditorField::create('QuickFeatures') |
||
220 | ->addExtraClass('stacked'), |
||
221 | )); |
||
222 | |||
223 | if ($this->ID) { |
||
224 | // Categories |
||
225 | $config = GridFieldConfig_RelationEditor::create(); |
||
226 | $config->addComponent(new GridFieldOrderableRows('SortOrder')); |
||
227 | $config->removeComponentsByType(GridFieldAddExistingAutocompleter::class); |
||
228 | $config->addComponent(new GridFieldAddExistingSearchButton()); |
||
229 | $config->removeComponentsByType(GridFieldAddNewButton::class); |
||
230 | $categories = $this->Categories()->sort('SortOrder'); |
||
231 | $categoryField = GridField::create('Categories', 'Categories', $categories, $config); |
||
232 | |||
233 | $fields->addFieldsToTab('Root.Categories.Categories', array( |
||
234 | $categoryField, |
||
235 | )); |
||
236 | |||
237 | // Care and Cleaning |
||
238 | $config = GridFieldConfig_RecordEditor::create(); |
||
239 | $config->addComponent(new GridFieldOrderableRows('Sort')); |
||
240 | $config->removeComponentsByType(GridFieldAddExistingAutocompleter::class); |
||
241 | $config->addComponent(new GridFieldAddExistingSearchButton()); |
||
242 | $operation = GridField::create( |
||
243 | 'CareCleaningDocs', |
||
244 | 'Care and Cleaning', |
||
245 | $this->CareCleaningDocs()->sort('Sort'), |
||
246 | $config |
||
247 | ); |
||
248 | $fields->addFieldsToTab('Root.Files.Care', array( |
||
249 | $operation, |
||
250 | )); |
||
251 | |||
252 | // Operation Manuals |
||
253 | $config = GridFieldConfig_RecordEditor::create(); |
||
254 | $config->addComponent(new GridFieldOrderableRows('Sort')); |
||
255 | $config->removeComponentsByType(GridFieldAddExistingAutocompleter::class); |
||
256 | $config->addComponent(new GridFieldAddExistingSearchButton()); |
||
257 | $operation = GridField::create( |
||
258 | 'OperationManuals', |
||
259 | 'Operation Manuals', |
||
260 | $this->OperationManuals()->sort('Sort'), |
||
261 | $config |
||
262 | ); |
||
263 | $fields->addFieldsToTab('Root.Files.Operation', array( |
||
264 | $operation, |
||
265 | )); |
||
266 | |||
267 | // Spec Sheets |
||
268 | $config = GridFieldConfig_RecordEditor::create(); |
||
269 | $config->addComponent(new GridFieldOrderableRows('Sort')); |
||
270 | $config->removeComponentsByType(GridFieldAddExistingAutocompleter::class); |
||
271 | $config->addComponent(new GridFieldAddExistingSearchButton()); |
||
272 | $specsheets = GridField::create('SpecSheets', 'Spec Sheets', $this->SpecSheets()->sort('Sort'), $config); |
||
273 | $fields->addFieldsToTab('Root.Files.SpecSheets', array( |
||
274 | $specsheets, |
||
275 | )); |
||
276 | |||
277 | // Warranties |
||
278 | $config = GridFieldConfig_RecordEditor::create(); |
||
279 | $config->addComponent(new GridFieldOrderableRows('Sort')); |
||
280 | $config->removeComponentsByType(GridFieldAddExistingAutocompleter::class); |
||
281 | $config->addComponent(new GridFieldAddExistingSearchButton()); |
||
282 | $warranties = GridField::create('Warranties', 'Warranties', $this->Warranties()->sort('Sort'), $config); |
||
283 | $fields->addFieldsToTab('Root.Files.Warranty', array( |
||
284 | $warranties, |
||
285 | )); |
||
286 | } |
||
287 | |||
288 | return $fields; |
||
289 | } |
||
393 |