| Conditions | 15 |
| Paths | 81 |
| Total Lines | 80 |
| Code Lines | 51 |
| 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 |
||
| 88 | public function getCMSFields() |
||
| 89 | { |
||
| 90 | $fields = $this->scaffoldFormFields(array( |
||
| 91 | 'includeRelations' => ($this->ID > 0), |
||
| 92 | 'tabbed' => true, |
||
| 93 | 'ajaxSafe' => true |
||
| 94 | )); |
||
| 95 | |||
| 96 | $fields->insertAfter(new ReadonlyField('ClassNameTranslated', _t('BaseElement.TYPE', 'Type'), $this->i18n_singular_name()), 'Title'); |
||
| 97 | $fields->removeByName('ListID'); |
||
| 98 | $fields->removeByName('ParentID'); |
||
| 99 | $fields->removeByName('Sort'); |
||
| 100 | $fields->removeByName('ExtraClass'); |
||
| 101 | |||
| 102 | if (!$this->config()->enable_title_in_template) { |
||
| 103 | $fields->removeByName('HideTitle'); |
||
| 104 | $title = $fields->fieldByName('Root.Main.Title'); |
||
| 105 | |||
| 106 | if ($title) { |
||
| 107 | $title->setRightTitle('For reference only. Does not appear in the template.'); |
||
| 108 | } |
||
| 109 | } |
||
| 110 | |||
| 111 | $fields->addFieldToTab('Root.Settings', new TextField('ExtraClass', 'Extra CSS Classes to add')); |
||
| 112 | |||
| 113 | if (!is_a($this, 'ElementList')) { |
||
| 114 | $lists = ElementList::get()->filter('ParentID', $this->ParentID); |
||
| 115 | |||
| 116 | if ($lists->exists()) { |
||
| 117 | $fields->addFieldToTab('Root.Settings', |
||
| 118 | $move = new DropdownField('MoveToListID', 'Move this to another list', $lists->map('ID', 'CMSTitle'), '') |
||
| 119 | ); |
||
| 120 | |||
| 121 | $move->setEmptyString('Select a list..'); |
||
| 122 | $move->setHasEmptyDefault(true); |
||
| 123 | } |
||
| 124 | } |
||
| 125 | |||
| 126 | |||
| 127 | if($virtual = $fields->dataFieldByName('VirtualClones')) { |
||
| 128 | if($this->Parent() && $this->Parent()->exists() && $this->Parent()->getOwnerPage() && $this->Parent()->getOwnerPage()->exists()) { |
||
| 129 | $tab = $fields->findOrMakeTab('Root.VirtualClones'); |
||
| 130 | $tab->setTitle(_t('BaseElement.VIRTUALTABTITLE', 'Linked To')); |
||
| 131 | |||
| 132 | $ownerPage = $this->Parent()->getOwnerPage(); |
||
| 133 | $tab->push(new LiteralField('DisplaysOnPage', sprintf( |
||
| 134 | "<p>The original content block appears on <a href='%s'>%s</a></p>", |
||
| 135 | ($ownerPage->hasMethod('CMSEditLink') && $ownerPage->canEdit()) ? $ownerPage->CMSEditLink() : $ownerPage->Link(), |
||
| 136 | $ownerPage->MenuTitle |
||
| 137 | ))); |
||
| 138 | |||
| 139 | $virtual->setConfig(new GridFieldConfig_Base()); |
||
| 140 | $virtual |
||
| 141 | ->setTitle(_t('BaseElement.OTHERPAGES', 'Other pages')) |
||
| 142 | ->getConfig() |
||
| 143 | ->removeComponentsByType('GridFieldAddExistingAutocompleter') |
||
| 144 | ->removeComponentsByType('GridFieldAddNewButton') |
||
| 145 | ->removeComponentsByType('GridFieldDeleteAction') |
||
| 146 | ->removeComponentsByType('GridFieldDetailForm') |
||
| 147 | ->addComponent(new ElementalGridFieldDeleteAction()); |
||
| 148 | |||
| 149 | $virtual->getConfig() |
||
| 150 | ->getComponentByType('GridFieldDataColumns') |
||
| 151 | ->setDisplayFields(array( |
||
| 152 | 'getPage.Title' => 'Title', |
||
| 153 | 'getPage.Link' => 'Link' |
||
| 154 | )); |
||
| 155 | } |
||
| 156 | } |
||
| 157 | |||
| 158 | $this->extend('updateCMSFields', $fields); |
||
| 159 | |||
| 160 | if ($this->IsInDB()) { |
||
| 161 | if ($this->isEndofLine('BaseElement') && $this->hasExtension('VersionViewerDataObject')) { |
||
| 162 | $fields = $this->addVersionViewer($fields, $this); |
||
| 163 | } |
||
| 164 | } |
||
| 165 | |||
| 166 | return $fields; |
||
| 167 | } |
||
| 168 | |||
| 378 |
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.