| Conditions | 3 | 
| Paths | 1 | 
| Total Lines | 170 | 
| Code Lines | 122 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 3 | ||
| 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  | 
            ||
| 148 | public function getCMSFields()  | 
            ||
| 149 |     { | 
            ||
| 150 |         $this->beforeUpdateCMSFields(function (FieldList $fields) { | 
            ||
| 151 | $fields->removeByName([  | 
            ||
| 152 | 'Images',  | 
            ||
| 153 | 'WeightModifier',  | 
            ||
| 154 | 'CodeModifier',  | 
            ||
| 155 | 'PriceModifier',  | 
            ||
| 156 | 'WeightModifierAction',  | 
            ||
| 157 | 'CodeModifierAction',  | 
            ||
| 158 | 'PriceModifierAction',  | 
            ||
| 159 | 'Available',  | 
            ||
| 160 | 'Type',  | 
            ||
| 161 | 'OptionModifierKey',  | 
            ||
| 162 | 'SortOrder',  | 
            ||
| 163 | 'ProductID',  | 
            ||
| 164 | 'FinalPrice',  | 
            ||
| 165 | 'FinalWeight',  | 
            ||
| 166 | 'FinalCode',  | 
            ||
| 167 | ]);  | 
            ||
| 168 | |||
| 169 | $fields->insertBefore(  | 
            ||
| 170 | 'Content',  | 
            ||
| 171 |                 CheckboxField::create('Available') | 
            ||
| 172 |                     ->setTitle('Available for purchase') | 
            ||
| 173 | );  | 
            ||
| 174 | |||
| 175 | $fields->insertBefore(  | 
            ||
| 176 | 'Content',  | 
            ||
| 177 |                 $fields->dataFieldByName('VariationTypeID') | 
            ||
| 178 | );  | 
            ||
| 179 | |||
| 180 | $fields->insertBefore(  | 
            ||
| 181 | 'Content',  | 
            ||
| 182 |                 $fields->dataFieldByName('UseProductContent') | 
            ||
| 183 | );  | 
            ||
| 184 | |||
| 185 |             $content = $fields->dataFieldByName('Content'); | 
            ||
| 186 | |||
| 187 |             $content->hideUnless('UseProductContent')->isNotChecked()->end(); | 
            ||
| 188 | |||
| 189 |             if ($this->exists()) { | 
            ||
| 190 | $fields->addFieldToTab(  | 
            ||
| 191 | 'Root.ProductModifications',  | 
            ||
| 192 |                     ReadonlyField::create('OptionModifierKey') | 
            ||
| 193 |                         ->setTitle(_t('Variation.ModifierKey', 'Modifier Key')) | 
            ||
| 194 | );  | 
            ||
| 195 | }  | 
            ||
| 196 | |||
| 197 |             if ($this->Product()->hasDatabaseField('Weight')) { | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 198 | $fields->addFieldtoTab(  | 
            ||
| 199 | 'Root.ProductModifications',  | 
            ||
| 200 | FieldGroup::create(  | 
            ||
| 201 | DropdownField::create(  | 
            ||
| 202 | 'WeightModifierAction',  | 
            ||
| 203 |                             _t('Variation.WeightModifierAction', 'Weight Modification Type'), | 
            ||
| 204 | [  | 
            ||
| 205 | 'Add' => _t(  | 
            ||
| 206 | 'Variation.WeightAdd',  | 
            ||
| 207 | 'Add to Base Weight',  | 
            ||
| 208 | 'Add to weight'  | 
            ||
| 209 | ),  | 
            ||
| 210 | 'Subtract' => _t(  | 
            ||
| 211 | 'Variation.WeightSubtract',  | 
            ||
| 212 | 'Subtract from Base Weight',  | 
            ||
| 213 | 'Subtract from weight'  | 
            ||
| 214 | ),  | 
            ||
| 215 |                                 'Set' => _t('Variation.WeightSet', 'Set as a new Weight'), | 
            ||
| 216 | ]  | 
            ||
| 217 | )  | 
            ||
| 218 |                             ->setEmptyString('') | 
            ||
| 219 | ->setDescription(_t(  | 
            ||
| 220 | 'Variation.WeightDescription',  | 
            ||
| 221 | 'Does weight modify or replace base weight?'  | 
            ||
| 222 | )),  | 
            ||
| 223 |                         NumericField::create("WeightModifier") | 
            ||
| 224 |                             ->setTitle(_t('Variation.WeightModifier', 'Weight')) | 
            ||
| 225 | ->setScale(3)  | 
            ||
| 226 | ->setDescription(_t(  | 
            ||
| 227 | 'Variation.WeightDescription',  | 
            ||
| 228 | 'Only supports up to 3 decimal places'  | 
            ||
| 229 |                             ))->displayIf('WeightModifierAction')->isNotEmpty()->end(), | 
            ||
| 230 |                         NumericField::create('FinalWeight') | 
            ||
| 231 |                             ->setTitle('Final Modified Weight') | 
            ||
| 232 |                             ->setDescription("Product's weight is {$this->Product()->Weight}") | 
            ||
| 233 | ->performDisabledTransformation()  | 
            ||
| 234 |                     )->setTitle('Weight Modification') | 
            ||
| 235 | );  | 
            ||
| 236 | }  | 
            ||
| 237 | |||
| 238 | $fields->addFieldsToTab(  | 
            ||
| 239 | 'Root.ProductModifications',  | 
            ||
| 240 | [  | 
            ||
| 241 | // Price Modifier Fields  | 
            ||
| 242 |                     //HeaderField::create('PriceHD', _t('Variation.PriceHD', 'Modify Price'), 4), | 
            ||
| 243 | FieldGroup::create(  | 
            ||
| 244 | DropdownField::create(  | 
            ||
| 245 | 'PriceModifierAction',  | 
            ||
| 246 |                             _t('Variation.PriceModifierAction', 'Price Modification Type'), | 
            ||
| 247 | [  | 
            ||
| 248 | 'Add' => _t(  | 
            ||
| 249 | 'Variation.PriceAdd',  | 
            ||
| 250 | 'Add to Base Price',  | 
            ||
| 251 | 'Add to price'  | 
            ||
| 252 | ),  | 
            ||
| 253 | 'Subtract' => _t(  | 
            ||
| 254 | 'Variation.PriceSubtract',  | 
            ||
| 255 | 'Subtract from Base Price',  | 
            ||
| 256 | 'Subtract from price'  | 
            ||
| 257 | ),  | 
            ||
| 258 |                                 'Set' => _t('Variation.PriceSet', 'Set as a new Price'), | 
            ||
| 259 | ]  | 
            ||
| 260 | )  | 
            ||
| 261 |                             ->setEmptyString('') | 
            ||
| 262 |                             ->setDescription(_t('Variation.PriceDescription', 'Does price modify or replace base price?')), | 
            ||
| 263 |                         CurrencyField::create('PriceModifier') | 
            ||
| 264 |                             ->setTitle(_t('Variation.PriceModifier', 'Price')) | 
            ||
| 265 |                             ->displayIf('PriceModifierAction')->isNotEmpty()->end(), | 
            ||
| 266 |                         CurrencyField::create('FinalPrice') | 
            ||
| 267 |                             ->setTitle('Final Modified Price') | 
            ||
| 268 |                             ->setDescription("Product's price is {$this->Product()->Price}") | 
            ||
| 269 | ->performDisabledTransformation()  | 
            ||
| 270 |                     )->setTitle('Price Modifications'), | 
            ||
| 271 | |||
| 272 | // Code Modifier Fields  | 
            ||
| 273 |                     //HeaderField::create('CodeHD', _t('Variation.CodeHD', 'Modify Code'), 4), | 
            ||
| 274 | FieldGroup::create(  | 
            ||
| 275 | DropdownField::create(  | 
            ||
| 276 | 'CodeModifierAction',  | 
            ||
| 277 |                             _t('Variation.CodeModifierAction', 'Code Modification Type'), | 
            ||
| 278 | [  | 
            ||
| 279 | 'Add' => _t(  | 
            ||
| 280 | 'Variation.CodeAdd',  | 
            ||
| 281 | 'Add to Base Code',  | 
            ||
| 282 | 'Add to code'  | 
            ||
| 283 | ),  | 
            ||
| 284 | 'Subtract' => _t(  | 
            ||
| 285 | 'Variation.CodeSubtract',  | 
            ||
| 286 | 'Subtract from Base Code',  | 
            ||
| 287 | 'Subtract from code'  | 
            ||
| 288 | ),  | 
            ||
| 289 |                                 'Set' => _t('Variation.CodeSet', 'Set as a new Code'), | 
            ||
| 290 | ]  | 
            ||
| 291 | )  | 
            ||
| 292 |                             ->setEmptyString('') | 
            ||
| 293 |                             ->setDescription(_t('Variation.CodeDescription', 'Does code modify or replace base code?')), | 
            ||
| 294 |                         TextField::create('CodeModifier') | 
            ||
| 295 |                             ->setTitle(_t('Variation.CodeModifier', 'Code')) | 
            ||
| 296 |                             ->displayIf('CodeModifierAction')->isNotEmpty()->end(), | 
            ||
| 297 |                         TextField::create('FinalCode') | 
            ||
| 298 |                             ->setTitle('Final Modified Code') | 
            ||
| 299 |                             ->setDescription("Product's code is {$this->Product()->Code}") | 
            ||
| 300 | ->performDisabledTransformation()  | 
            ||
| 301 |                     )->setTitle('Code Modification'), | 
            ||
| 302 | ]  | 
            ||
| 303 | );  | 
            ||
| 304 | |||
| 305 | // Images tab  | 
            ||
| 306 |             $images = SortableUploadField::create('Images') | 
            ||
| 307 |                 ->setSortColumn('SortOrder') | 
            ||
| 308 | ->setIsMultiUpload(true)  | 
            ||
| 309 |                 ->setAllowedExtensions($this->config()->get('allowed_images_extensions')) | 
            ||
| 310 |                 ->setFolderName('Uploads/Products/Images'); | 
            ||
| 311 | |||
| 312 |             $fields->addFieldsToTab('Root.Images', [ | 
            ||
| 313 | $images,  | 
            ||
| 314 | ]);  | 
            ||
| 315 | });  | 
            ||
| 316 | |||
| 317 | return parent::getCMSFields();  | 
            ||
| 318 | }  | 
            ||
| 526 |