| Conditions | 2 |
| Paths | 2 |
| Total Lines | 105 |
| Code Lines | 76 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 |
||
| 164 | public function updateCMSFields(FieldList $fields) |
||
| 165 | { |
||
| 166 | $fields->removeByName([ |
||
| 167 | 'SKU', |
||
| 168 | ]); |
||
| 169 | |||
| 170 | $fields->addFieldsToTab( |
||
| 171 | 'Root.Ecommerce', |
||
| 172 | [ |
||
| 173 | CurrencyField::create('Price') |
||
| 174 | ->setDescription(_t( |
||
| 175 | __CLASS__ . '.PriceDescription', |
||
| 176 | 'Base price for this product. Can be modified using Product Options' |
||
| 177 | )), |
||
| 178 | TextField::create('Code') |
||
| 179 | ->setDescription(_t( |
||
| 180 | __CLASS__ . '.CodeDescription', |
||
| 181 | 'Required, must be unique. Product identifier used by FoxyCart in transactions. All leading and trailing spaces are removed on save.' |
||
| 182 | )), |
||
| 183 | DropdownField::create('FoxyCategoryID') |
||
| 184 | ->setTitle($this->owner->fieldLabel('FoxyCategoryID')) |
||
| 185 | ->setSource(FoxyCategory::get()->map()) |
||
| 186 | ->setDescription(_t( |
||
| 187 | __CLASS__ . '.FoxyCategoryDescription', |
||
| 188 | 'Required. Must also exist in |
||
| 189 | <a href="https://admin.foxycart.com/admin.php?ThisAction=ManageProductCategories" |
||
| 190 | target="_blank"> |
||
| 191 | Foxy Categories |
||
| 192 | </a>. |
||
| 193 | Used to set category specific options like shipping and taxes. Managed in Foxy > Categories' |
||
| 194 | )) |
||
| 195 | ->setEmptyString(''), |
||
| 196 | TextField::create('ReceiptTitle') |
||
| 197 | ->setDescription(_t( |
||
| 198 | __CLASS__ . '.ReceiptTitleDescription', |
||
| 199 | 'Optional. Alternate title to display on order receipt' |
||
| 200 | )), |
||
| 201 | ], |
||
| 202 | 'Content' |
||
| 203 | ); |
||
| 204 | |||
| 205 | if ($this->owner->exists()) { |
||
| 206 | $config = GridFieldConfig_RelationEditor::create(); |
||
| 207 | $config |
||
| 208 | ->addComponents([ |
||
| 209 | new GridFieldOrderableRows('SortOrder'), |
||
| 210 | new GridFieldAddExistingSearchButton(), |
||
| 211 | ]) |
||
| 212 | ->removeComponentsByType([ |
||
| 213 | GridFieldAddExistingAutocompleter::class, |
||
| 214 | ]); |
||
| 215 | $options = GridField::create( |
||
| 216 | 'Options', |
||
| 217 | 'Options', |
||
| 218 | $this->owner->Options()->sort('SortOrder'), |
||
| 219 | $config |
||
| 220 | ); |
||
| 221 | |||
| 222 | $fields->addFieldsToTab( |
||
| 223 | 'Root.Options', |
||
| 224 | [ |
||
| 225 | $options, |
||
| 226 | ] |
||
| 227 | ); |
||
| 228 | |||
| 229 | $variationsConfig = GridFieldConfig_RelationEditor::create() |
||
| 230 | ->removeComponentsByType([ |
||
| 231 | GridFieldAddExistingAutocompleter::class, |
||
| 232 | GridFieldPaginator::class, |
||
| 233 | GridFieldPageCount::class, |
||
| 234 | GridFieldSortableHeader::class, |
||
| 235 | ]) |
||
| 236 | ->addComponents([ |
||
| 237 | new GridFieldOrderableRows('SortOrder'), |
||
| 238 | new GridFieldTitleHeader(), |
||
| 239 | new GridFieldGroupable( |
||
| 240 | 'VariationTypeID', // The fieldname to set the Group |
||
| 241 | 'Variation Type', // A description of the function of the group |
||
| 242 | 'none', // A title/header for items without a group/unassigned |
||
| 243 | VariationType::get()->sort('SortOrder')->map()->toArray() |
||
| 244 | ) |
||
| 245 | ]); |
||
| 246 | |||
| 247 | $fields->addFieldToTab( |
||
| 248 | 'Root.Variations', |
||
| 249 | GridField::create( |
||
| 250 | 'Variations', |
||
| 251 | 'Variations', |
||
| 252 | $this->owner->Variations(), |
||
| 253 | $variationsConfig |
||
| 254 | ) |
||
| 255 | ); |
||
| 256 | } |
||
| 257 | |||
| 258 | $fields->addFieldsToTab( |
||
| 259 | 'Root.Inventory', |
||
| 260 | [ |
||
| 261 | NumericField::create('QuantityMax') |
||
| 262 | ->setTitle('Maximum quantity allowed in the cart') |
||
| 263 | ->setDescription('For unlimited enter 0') |
||
| 264 | ->addExtraClass('stacked'), |
||
| 265 | CheckboxField::create('Available') |
||
| 266 | ->setDescription(_t( |
||
| 267 | __CLASS__ . '.AvailableDescription', |
||
| 268 | 'If unchecked, will remove "Add to Cart" form and instead display "Currently unavailable"' |
||
| 269 | )), |
||
| 415 |