| Conditions | 2 |
| Paths | 2 |
| Total Lines | 82 |
| Code Lines | 61 |
| 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 |
||
| 132 | public function updateCMSFields(FieldList $fields) |
||
| 133 | { |
||
| 134 | $fields->removeByName([ |
||
| 135 | 'SKU', |
||
| 136 | ]); |
||
| 137 | |||
| 138 | $fields->addFieldsToTab( |
||
| 139 | 'Root.Ecommerce', |
||
| 140 | [ |
||
| 141 | CurrencyField::create('Price') |
||
| 142 | ->setDescription(_t( |
||
| 143 | __CLASS__ . '.PriceDescription', |
||
| 144 | 'Base price for this product. Can be modified using Product variations' |
||
| 145 | )), |
||
| 146 | TextField::create('Code') |
||
| 147 | ->setDescription(_t( |
||
| 148 | __CLASS__ . '.CodeDescription', |
||
| 149 | 'Required, must be unique. Product identifier used by FoxyCart in transactions. All leading and trailing spaces are removed on save.' |
||
| 150 | )), |
||
| 151 | DropdownField::create('FoxyCategoryID') |
||
| 152 | ->setTitle($this->owner->fieldLabel('FoxyCategoryID')) |
||
| 153 | ->setSource(FoxyCategory::get()->map()) |
||
| 154 | ->setDescription(_t( |
||
| 155 | __CLASS__ . '.FoxyCategoryDescription', |
||
| 156 | 'Required. Must also exist in |
||
| 157 | <a href="https://admin.foxycart.com/admin.php?ThisAction=ManageProductCategories" |
||
| 158 | target="_blank"> |
||
| 159 | Foxy Categories |
||
| 160 | </a>. |
||
| 161 | Used to set category specific options like shipping and taxes. Managed in Foxy > Categories' |
||
| 162 | )) |
||
| 163 | ->setEmptyString(''), |
||
| 164 | TextField::create('ReceiptTitle') |
||
| 165 | ->setDescription(_t( |
||
| 166 | __CLASS__ . '.ReceiptTitleDescription', |
||
| 167 | 'Optional. Alternate title to display on order receipt' |
||
| 168 | )), |
||
| 169 | ], |
||
| 170 | 'Content' |
||
| 171 | ); |
||
| 172 | |||
| 173 | if ($this->owner->exists()) { |
||
| 174 | $variationsConfig = GridFieldConfig_RelationEditor::create() |
||
| 175 | ->removeComponentsByType([ |
||
| 176 | GridFieldAddExistingAutocompleter::class, |
||
| 177 | GridFieldPaginator::class, |
||
| 178 | GridFieldPageCount::class, |
||
| 179 | GridFieldSortableHeader::class, |
||
| 180 | ]) |
||
| 181 | ->addComponents([ |
||
| 182 | new GridFieldOrderableRows('SortOrder'), |
||
| 183 | new GridFieldTitleHeader(), |
||
| 184 | new GridFieldGroupable( |
||
| 185 | 'VariationTypeID', // The fieldname to set the Group |
||
| 186 | 'Variation Type', // A description of the function of the group |
||
| 187 | 'none', // A title/header for items without a group/unassigned |
||
| 188 | VariationType::get()->sort('SortOrder')->map()->toArray() |
||
| 189 | ) |
||
| 190 | ]); |
||
| 191 | |||
| 192 | $fields->addFieldToTab( |
||
| 193 | 'Root.Variations', |
||
| 194 | GridField::create( |
||
| 195 | 'Variations', |
||
| 196 | 'Variations', |
||
| 197 | $this->owner->Variations(), |
||
| 198 | $variationsConfig |
||
| 199 | ) |
||
| 200 | ); |
||
| 201 | } |
||
| 202 | |||
| 203 | $fields->addFieldsToTab( |
||
| 204 | 'Root.Inventory', |
||
| 205 | [ |
||
| 206 | NumericField::create('QuantityMax') |
||
| 207 | ->setTitle('Maximum quantity allowed in the cart') |
||
| 208 | ->setDescription('For unlimited enter 0') |
||
| 209 | ->addExtraClass('stacked'), |
||
| 210 | CheckboxField::create('Available') |
||
| 211 | ->setDescription(_t( |
||
| 212 | __CLASS__ . '.AvailableDescription', |
||
| 213 | 'If unchecked, will remove "Add to Cart" form and instead display "Currently unavailable"' |
||
| 214 | )), |
||
| 372 |