| Conditions | 5 | 
| Paths | 1 | 
| Total Lines | 57 | 
| Code Lines | 37 | 
| 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($autocompleter = new ElementalGridFieldAddExistingAutocompleter('buttons-before-right')); | 
            ||
| 63 | |||
| 64 |                 if ($this->owner->canDelete()) { | 
            ||
| 65 | $config->addComponent(new ElementalGridFieldDeleteAction());  | 
            ||
| 66 | }  | 
            ||
| 67 | |||
| 68 |                 if($list) { | 
            ||
| 69 | $autocompleter->setSearchList(  | 
            ||
| 70 |                         BaseElement::get()->filter('ClassName', array_keys($list)) | 
            ||
| 71 | );  | 
            ||
| 72 | }  | 
            ||
| 73 | |||
| 74 | $widgetArea = new GridField(  | 
            ||
| 75 | 'Elements',  | 
            ||
| 76 |                     Config::inst()->get("ElementPageExtension", 'elements_title'), | 
            ||
| 77 | $elements,  | 
            ||
| 78 | $config  | 
            ||
| 79 | );  | 
            ||
| 80 | |||
| 81 |                 $fields->addFieldToTab('Root.Main', $widgetArea); | 
            ||
| 82 |             } else { | 
            ||
| 83 |                 $fields->addFieldToTab('Root.Main', LiteralField::create('warn', '<p class="message notice">Once you save this object you will be able to add items</p>')); | 
            ||
| 84 | }  | 
            ||
| 85 | });  | 
            ||
| 86 | |||
| 87 | return parent::getCMSFields();  | 
            ||
| 88 | }  | 
            ||
| 89 | |||
| 160 | 
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.