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