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