| Conditions | 2 |
| Paths | 1 |
| Total Lines | 116 |
| Code Lines | 74 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 99 | public function getCMSFields() |
||
| 100 | { |
||
| 101 | $this->beforeUpdateCMSFields(function (FieldList $fields) { |
||
| 102 | $fields->removeByName([ |
||
| 103 | 'Images', |
||
| 104 | 'OptionModifierKey', |
||
| 105 | ]); |
||
| 106 | |||
| 107 | // Images tab |
||
| 108 | $images = SortableUploadField::create('Images') |
||
| 109 | ->setSortColumn('SortOrder') |
||
| 110 | ->setIsMultiUpload(true) |
||
| 111 | ->setAllowedExtensions($this->config()->get('allowed_images_extensions')) |
||
| 112 | ->setFolderName('Uploads/Products/Images'); |
||
| 113 | |||
| 114 | $fields->addFieldsToTab('Root.Images', [ |
||
| 115 | $images, |
||
| 116 | ]); |
||
| 117 | |||
| 118 | if ($this->exists()) { |
||
| 119 | $fields->addFieldToTab( |
||
| 120 | 'Root.Main', |
||
| 121 | ReadonlyField::create('OptionModifierKey') |
||
| 122 | ->setTitle(_t('Variation.ModifierKey', 'Modifier Key')) |
||
| 123 | ); |
||
| 124 | } |
||
| 125 | |||
| 126 | $fields->addFieldsToTab( |
||
| 127 | 'Root.Main', |
||
| 128 | [ |
||
| 129 | CheckboxField::create('Available', 'Available for purchase'), |
||
| 130 | |||
| 131 | // Weight Modifier Fields |
||
| 132 | //HeaderField::create('WeightHD', _t('Variation.WeightHD', 'Modify Weight'), 4), |
||
| 133 | NumericField::create("WeightModifier") |
||
| 134 | ->setTitle(_t('Variation.WeightModifier', 'Weight')) |
||
| 135 | ->setScale(3) |
||
| 136 | ->setDescription(_t( |
||
| 137 | 'Variation.WeightDescription', |
||
| 138 | 'Only supports up to 3 decimal places' |
||
| 139 | )), |
||
| 140 | DropdownField::create( |
||
| 141 | 'WeightModifierAction', |
||
| 142 | _t('Variation.WeightModifierAction', 'Weight Modification'), |
||
| 143 | [ |
||
| 144 | 'Add' => _t( |
||
| 145 | 'Variation.WeightAdd', |
||
| 146 | 'Add to Base Weight', |
||
| 147 | 'Add to weight' |
||
| 148 | ), |
||
| 149 | 'Subtract' => _t( |
||
| 150 | 'Variation.WeightSubtract', |
||
| 151 | 'Subtract from Base Weight', |
||
| 152 | 'Subtract from weight' |
||
| 153 | ), |
||
| 154 | 'Set' => _t('Variation.WeightSet', 'Set as a new Weight'), |
||
| 155 | ] |
||
| 156 | ) |
||
| 157 | ->setEmptyString('') |
||
| 158 | ->setDescription(_t( |
||
| 159 | 'Variation.WeightDescription', |
||
| 160 | 'Does weight modify or replace base weight?' |
||
| 161 | )), |
||
| 162 | |||
| 163 | // Price Modifier Fields |
||
| 164 | //HeaderField::create('PriceHD', _t('Variation.PriceHD', 'Modify Price'), 4), |
||
| 165 | CurrencyField::create('PriceModifier') |
||
| 166 | ->setTitle(_t('Variation.PriceModifier', 'Price')), |
||
| 167 | DropdownField::create( |
||
| 168 | 'PriceModifierAction', |
||
| 169 | _t('Variation.PriceModifierAction', 'Price Modification'), |
||
| 170 | [ |
||
| 171 | 'Add' => _t( |
||
| 172 | 'Variation.PriceAdd', |
||
| 173 | 'Add to Base Price', |
||
| 174 | 'Add to price' |
||
| 175 | ), |
||
| 176 | 'Subtract' => _t( |
||
| 177 | 'Variation.PriceSubtract', |
||
| 178 | 'Subtract from Base Price', |
||
| 179 | 'Subtract from price' |
||
| 180 | ), |
||
| 181 | 'Set' => _t('Variation.PriceSet', 'Set as a new Price'), |
||
| 182 | ] |
||
| 183 | ) |
||
| 184 | ->setEmptyString('') |
||
| 185 | ->setDescription(_t('Variation.PriceDescription', 'Does price modify or replace base price?')), |
||
| 186 | |||
| 187 | // Code Modifier Fields |
||
| 188 | //HeaderField::create('CodeHD', _t('Variation.CodeHD', 'Modify Code'), 4), |
||
| 189 | TextField::create('CodeModifier') |
||
| 190 | ->setTitle(_t('Variation.CodeModifier', 'Code')), |
||
| 191 | DropdownField::create( |
||
| 192 | 'CodeModifierAction', |
||
| 193 | _t('Variation.CodeModifierAction', 'Code Modification'), |
||
| 194 | [ |
||
| 195 | 'Add' => _t( |
||
| 196 | 'Variation.CodeAdd', |
||
| 197 | 'Add to Base Code', |
||
| 198 | 'Add to code' |
||
| 199 | ), |
||
| 200 | 'Subtract' => _t( |
||
| 201 | 'Variation.CodeSubtract', |
||
| 202 | 'Subtract from Base Code', |
||
| 203 | 'Subtract from code' |
||
| 204 | ), |
||
| 205 | 'Set' => _t('Variation.CodeSet', 'Set as a new Code'), |
||
| 206 | ] |
||
| 207 | ) |
||
| 208 | ->setEmptyString('') |
||
| 209 | ->setDescription(_t('Variation.CodeDescription', 'Does code modify or replace base code?')), |
||
| 210 | ] |
||
| 211 | ); |
||
| 212 | }); |
||
| 213 | |||
| 214 | return parent::getCMSFields(); |
||
| 215 | } |
||
| 306 |