| Conditions | 3 |
| Paths | 4 |
| Total Lines | 56 |
| Code Lines | 41 |
| 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 |
||
| 134 | public function getCMSFields() |
||
| 135 | { |
||
| 136 | $fields = parent::getCMSFields(); |
||
| 137 | $fields->removeFieldFromTab("Root", "Sort"); |
||
| 138 | $fields->removeFieldFromTab("Root.Main", "AdvertisementImage"); |
||
| 139 | $fields->removeFieldFromTab("Root.Main", "AdvertisementImageID"); |
||
| 140 | $fields->removeFieldFromTab("Root.Main", "LinkedPageID"); |
||
| 141 | $fields->removeFieldFromTab("Root.Main", "ExternalLink"); |
||
| 142 | $fields->removeFieldFromTab("Root.Parents", "Parents"); |
||
| 143 | $fields->removeFieldFromTab("Root", "Parents"); |
||
| 144 | $fields->addFieldToTab("Root.Main", ReadonlyField::create("Link", 'Calculated Link')); |
||
| 145 | $fields->addFieldToTab("Root.Main", $mainImageField = new UploadField($name = "AdvertisementImage", $title = $this->i18n_singular_name())); |
||
| 146 | $mainImageField->setRightTitle(self::recommended_image_size_statement()); |
||
| 147 | $fields->addFieldToTab( |
||
| 148 | "Root.Main", |
||
| 149 | $additionalImageField = UploadField::create( |
||
| 150 | $name = "AdditionalImage", |
||
| 151 | $title = $this->i18n_singular_name()." "._t("Advertisement.ADDITIONAL_IMAGE", "additional image") |
||
| 152 | ) |
||
| 153 | ); |
||
| 154 | $additionalImageField->setRightTitle(self::recommended_image_size_statement()); |
||
| 155 | if ($this->ID) { |
||
| 156 | $treeField = TreeMultiselectField::create( |
||
| 157 | "Parents", |
||
| 158 | _t("Advertisement.GETCMSFIELDSPARENTID", "only show on ... (leave blank to show on all " |
||
| 159 | .$this->i18n_singular_name() |
||
| 160 | ." pages)"), |
||
| 161 | "SiteTree" |
||
| 162 | ); |
||
| 163 | /*$callback = $this->callbackFilterFunctionForMultiSelect(); |
||
| 164 | if($callback) { |
||
| 165 | $treeField->setFilterFunction ($callback); |
||
| 166 | }*/ |
||
| 167 | $fields->addFieldToTab("Root.ShownOn", $treeField); |
||
| 168 | } |
||
| 169 | $fields->addFieldToTab( |
||
| 170 | "Root.OptionalLink", |
||
| 171 | $externalLinkField = new TextField($name = "ExternalLink", $title = _t("Advertisement.GETCMSFIELDSEXTERNALLINK", "link to external site")) |
||
| 172 | ); |
||
| 173 | $externalLinkField->setRightTitle(_t("Advertisement.GETCMSFIELDSEXTERNALLINK_EXPLANATION", "(e.g. http://www.wikipedia.org) - this will override an internal link")); |
||
| 174 | $fields->addFieldToTab("Root.OptionalLink", TreeDropdownField::create($name = "LinkedPageID", $title = _t("Advertisement.GETCMSFIELDSEXTERNALLINKID", "link to a page on this website"), $sourceObject = "SiteTree")); |
||
| 175 | if (class_exists("DataObjectSorterController")) { |
||
| 176 | //sorted on parent page... |
||
| 177 | } else { |
||
| 178 | $fields->addFieldToTab( |
||
| 179 | "Root.Position", |
||
| 180 | $sortField = NumericField::create( |
||
| 181 | "Sort", |
||
| 182 | _t("Advertisement.SORT", "Sort index number") |
||
| 183 | ) |
||
| 184 | ); |
||
| 185 | $sortField->setRightTitle(_t("Advertisement.SORT_EXPLANATION", "the lower the number, the earlier it shows")); |
||
| 186 | } |
||
| 187 | $fields->removeFieldFromTab("Root.Main", "AlternativeSortNumber"); |
||
| 188 | return $fields; |
||
| 189 | } |
||
| 190 | |||
| 274 |
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.