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