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