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