| Conditions | 9 |
| Paths | 54 |
| Total Lines | 67 |
| Code Lines | 41 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 15 | ||
| Bugs | 2 | Features | 2 |
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 |
||
| 55 | public function getCMSFields() |
||
| 56 | { |
||
| 57 | $fields = $this->scaffoldFormFields(array( |
||
| 58 | 'includeRelations' => ($this->ID > 0), |
||
| 59 | 'tabbed' => true, |
||
| 60 | 'ajaxSafe' => true |
||
| 61 | )); |
||
| 62 | |||
| 63 | $fields->insertAfter(new ReadonlyField('ClassNameTranslated', _t('BaseElement.TYPE', 'Type'), $this->i18n_singular_name()), 'Title'); |
||
| 64 | $fields->removeByName('ListID'); |
||
| 65 | $fields->removeByName('ParentID'); |
||
| 66 | $fields->removeByName('Sort'); |
||
| 67 | $fields->removeByName('ExtraClass'); |
||
| 68 | |||
| 69 | if (!$this->enable_title_in_template) { |
||
| 70 | $fields->removeByName('HideTitle'); |
||
| 71 | $title = $fields->fieldByName('Root.Main.Title'); |
||
| 72 | |||
| 73 | if ($title) { |
||
| 74 | $title->setRightTitle('For reference only. Does not appear in the template.'); |
||
| 75 | } |
||
| 76 | } |
||
| 77 | |||
| 78 | $fields->addFieldToTab('Root.Settings', new TextField('ExtraClass', 'Extra CSS Classes to add')); |
||
| 79 | |||
| 80 | if (!is_a($this, 'ElementList')) { |
||
| 81 | $lists = ElementList::get()->filter('ParentID', $this->ParentID); |
||
| 82 | |||
| 83 | if ($lists->exists()) { |
||
| 84 | $fields->addFieldToTab('Root.Main', |
||
| 85 | $move = new DropdownField('MoveToListID', 'Move this to another list', $lists->map('ID', 'CMSTitle'), '') |
||
| 86 | ); |
||
| 87 | |||
| 88 | $move->setEmptyString('Select a list..'); |
||
| 89 | $move->setHasEmptyDefault(true); |
||
| 90 | } |
||
| 91 | } |
||
| 92 | |||
| 93 | |||
| 94 | if($virtual = $fields->dataFieldByName('VirtualClones')) { |
||
| 95 | $tab = $fields->findOrMakeTab('Root.VirtualClones'); |
||
| 96 | $tab->setTitle(_t('BaseElement.VIRTUALTABTITLE', 'Linked To')); |
||
| 97 | |||
| 98 | $virtual |
||
| 99 | ->setTitle(_t('BaseElement.VIRTUALTABTITLE', 'Linked To')) |
||
| 100 | ->getConfig() |
||
| 101 | ->removeComponentsByType('GridFieldAddExistingAutocompleter') |
||
| 102 | ->removeComponentsByType('GridFieldAddNewButton'); |
||
| 103 | |||
| 104 | $virtual->getConfig() |
||
| 105 | ->getComponentByType('GridFieldDataColumns') |
||
| 106 | ->setDisplayFields(array( |
||
| 107 | 'Parent.getOwnerPage.Title' => 'Title', |
||
| 108 | 'Parent.getOwnerPage.Link' => 'Link' |
||
| 109 | )); |
||
| 110 | } |
||
| 111 | |||
| 112 | $this->extend('updateCMSFields', $fields); |
||
| 113 | |||
| 114 | if ($this->IsInDB()) { |
||
| 115 | if ($this->isEndofLine('BaseElement') && $this->hasExtension('VersionViewerDataObject')) { |
||
| 116 | $fields = $this->addVersionViewer($fields, $this); |
||
| 117 | } |
||
| 118 | } |
||
| 119 | |||
| 120 | return $fields; |
||
| 121 | } |
||
| 122 | |||
| 253 |
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.