| Conditions | 4 |
| Paths | 1 |
| Total Lines | 55 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 13 | ||
| Bugs | 1 | Features | 3 |
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 |
||
| 36 | public function getCMSFields() |
||
| 37 | { |
||
| 38 | $elements = $this->Elements(); |
||
| 39 | $isInDb = $this->isInDB(); |
||
| 40 | |||
| 41 | $this->beforeUpdateCMSFields(function ($fields) use ($elements, $isInDb) { |
||
| 42 | $fields->removeByName('Root.Elements'); |
||
| 43 | $fields->removeByName('Elements'); |
||
| 44 | |||
| 45 | $desc = HTMLEditorField::create('ListDescription', 'List Description'); |
||
| 46 | $desc->setRightTitle('Optional'); |
||
| 47 | $fields->addFieldToTab('Root.Main', $desc); |
||
| 48 | |||
| 49 | |||
| 50 | if ($isInDb) { |
||
| 51 | $adder = new ElementalGridFieldAddNewMultiClass(); |
||
| 52 | |||
| 53 | $list = $this->getAvailableTypes(); |
||
| 54 | |||
| 55 | if($list) { |
||
| 56 | $adder->setClasses($list); |
||
| 57 | } |
||
| 58 | |||
| 59 | $config = GridFieldConfig_RecordEditor::create(100); |
||
| 60 | $config->addComponent(new GridFieldSortableRows('Sort')); |
||
| 61 | $config->removeComponentsByType('GridFieldAddNewButton'); |
||
| 62 | $config->removeComponentsByType('GridFieldDeleteAction'); |
||
| 63 | $config->addComponent(new ElementalGridFieldDeleteAction()); |
||
| 64 | $config->addComponent($adder); |
||
| 65 | $config->addComponent($autocompleter = new ElementalGridFieldAddExistingAutocompleter()); |
||
| 66 | |||
| 67 | if($list) { |
||
| 68 | $autocompleter->setSearchList( |
||
| 69 | BaseElement::get()->filter('ClassName', array_keys($list)) |
||
| 70 | ); |
||
| 71 | } |
||
| 72 | |||
| 73 | $config->removeComponentsByType('GridFieldDetailForm'); |
||
| 74 | $config->addComponent(new VersionedDataObjectDetailsForm()); |
||
| 75 | |||
| 76 | $widgetArea = new GridField( |
||
| 77 | 'Elements', |
||
| 78 | Config::inst()->get("ElementPageExtension", 'elements_title'), |
||
| 79 | $elements, |
||
| 80 | $config |
||
| 81 | ); |
||
| 82 | |||
| 83 | $fields->addFieldToTab('Root.Main', $widgetArea); |
||
| 84 | } else { |
||
| 85 | $fields->addFieldToTab('Root.Main', LiteralField::create('warn', '<p class="message notice">Once you save this object you will be able to add items</p>')); |
||
| 86 | } |
||
| 87 | }); |
||
| 88 | |||
| 89 | return parent::getCMSFields(); |
||
| 90 | } |
||
| 91 | |||
| 158 |
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.