| Conditions | 3 | 
| Paths | 1 | 
| Total Lines | 175 | 
| Code Lines | 125 | 
| 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  | 
            ||
| 205 | public function getCMSFields()  | 
            ||
| 206 |     { | 
            ||
| 207 |         $this->beforeUpdateCMSFields(function (FieldList $fields) { | 
            ||
| 208 | $fields->removeByName([  | 
            ||
| 209 | 'Images',  | 
            ||
| 210 | 'WeightModifier',  | 
            ||
| 211 | 'CodeModifier',  | 
            ||
| 212 | 'PriceModifier',  | 
            ||
| 213 | 'WeightModifierAction',  | 
            ||
| 214 | 'CodeModifierAction',  | 
            ||
| 215 | 'PriceModifierAction',  | 
            ||
| 216 | 'Available',  | 
            ||
| 217 | 'Type',  | 
            ||
| 218 | 'OptionModifierKey',  | 
            ||
| 219 | 'SortOrder',  | 
            ||
| 220 | 'ProductID',  | 
            ||
| 221 | 'FinalPrice',  | 
            ||
| 222 | 'FinalWeight',  | 
            ||
| 223 | 'FinalCode',  | 
            ||
| 224 | 'IsDefault',  | 
            ||
| 225 | ]);  | 
            ||
| 226 | |||
| 227 | $fields->insertBefore(  | 
            ||
| 228 | 'Content',  | 
            ||
| 229 |                 CheckboxField::create('Available') | 
            ||
| 230 |                     ->setTitle('Available for purchase') | 
            ||
| 231 | );  | 
            ||
| 232 | |||
| 233 | $fields->insertBefore(  | 
            ||
| 234 | 'Content',  | 
            ||
| 235 |                 $fields->dataFieldByName('VariationTypeID') | 
            ||
| 236 | );  | 
            ||
| 237 | |||
| 238 | $fields->insertBefore(  | 
            ||
| 239 | 'Content',  | 
            ||
| 240 |                 $fields->dataFieldByName('UseProductContent') | 
            ||
| 241 | );  | 
            ||
| 242 | |||
| 243 |             $content = $fields->dataFieldByName('Content'); | 
            ||
| 244 | |||
| 245 |             $content->hideUnless('UseProductContent')->isNotChecked()->end(); | 
            ||
| 246 | |||
| 247 |             if ($this->exists()) { | 
            ||
| 248 | $fields->addFieldToTab(  | 
            ||
| 249 | 'Root.ProductModifications',  | 
            ||
| 250 |                     ReadonlyField::create('OptionModifierKey') | 
            ||
| 251 |                         ->setTitle(_t('Variation.ModifierKey', 'Modifier Key')) | 
            ||
| 252 | );  | 
            ||
| 253 | }  | 
            ||
| 254 | |||
| 255 |             if ($this->Product()->hasDatabaseField('Weight')) { | 
            ||
| 256 | $fields->addFieldtoTab(  | 
            ||
| 257 | 'Root.ProductModifications',  | 
            ||
| 258 | FieldGroup::create(  | 
            ||
| 259 | DropdownField::create(  | 
            ||
| 260 | 'WeightModifierAction',  | 
            ||
| 261 |                             _t('Variation.WeightModifierAction', 'Weight Modification Type'), | 
            ||
| 262 | [  | 
            ||
| 263 | 'Add' => _t(  | 
            ||
| 264 | 'Variation.WeightAdd',  | 
            ||
| 265 | 'Add to Base Weight',  | 
            ||
| 266 | 'Add to weight'  | 
            ||
| 267 | ),  | 
            ||
| 268 | 'Subtract' => _t(  | 
            ||
| 269 | 'Variation.WeightSubtract',  | 
            ||
| 270 | 'Subtract from Base Weight',  | 
            ||
| 271 | 'Subtract from weight'  | 
            ||
| 272 | ),  | 
            ||
| 273 |                                 'Set' => _t('Variation.WeightSet', 'Set as a new Weight'), | 
            ||
| 274 | ]  | 
            ||
| 275 | )  | 
            ||
| 276 |                             ->setEmptyString('') | 
            ||
| 277 | ->setDescription(_t(  | 
            ||
| 278 | 'Variation.WeightDescription',  | 
            ||
| 279 | 'Does weight modify or replace base weight?'  | 
            ||
| 280 | )),  | 
            ||
| 281 |                         NumericField::create("WeightModifier") | 
            ||
| 282 |                             ->setTitle(_t('Variation.WeightModifier', 'Weight')) | 
            ||
| 283 | ->setScale(3)  | 
            ||
| 284 | ->setDescription(_t(  | 
            ||
| 285 | 'Variation.WeightDescription',  | 
            ||
| 286 | 'Only supports up to 3 decimal places'  | 
            ||
| 287 |                             ))->displayIf('WeightModifierAction')->isNotEmpty()->end(), | 
            ||
| 288 |                         NumericField::create('FinalWeight') | 
            ||
| 289 |                             ->setTitle('Final Modified Weight') | 
            ||
| 290 |                             ->setDescription("Product's weight is {$this->Product()->Weight}") | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 291 | ->performDisabledTransformation()  | 
            ||
| 292 |                     )->setTitle('Weight Modification') | 
            ||
| 293 | );  | 
            ||
| 294 | }  | 
            ||
| 295 | |||
| 296 | $fields->addFieldsToTab(  | 
            ||
| 297 | 'Root.ProductModifications',  | 
            ||
| 298 | [  | 
            ||
| 299 | // Price Modifier Fields  | 
            ||
| 300 |                     //HeaderField::create('PriceHD', _t('Variation.PriceHD', 'Modify Price'), 4), | 
            ||
| 301 | FieldGroup::create(  | 
            ||
| 302 | DropdownField::create(  | 
            ||
| 303 | 'PriceModifierAction',  | 
            ||
| 304 |                             _t('Variation.PriceModifierAction', 'Price Modification Type'), | 
            ||
| 305 | [  | 
            ||
| 306 | 'Add' => _t(  | 
            ||
| 307 | 'Variation.PriceAdd',  | 
            ||
| 308 | 'Add to Base Price',  | 
            ||
| 309 | 'Add to price'  | 
            ||
| 310 | ),  | 
            ||
| 311 | 'Subtract' => _t(  | 
            ||
| 312 | 'Variation.PriceSubtract',  | 
            ||
| 313 | 'Subtract from Base Price',  | 
            ||
| 314 | 'Subtract from price'  | 
            ||
| 315 | ),  | 
            ||
| 316 |                                 'Set' => _t('Variation.PriceSet', 'Set as a new Price'), | 
            ||
| 317 | ]  | 
            ||
| 318 | )  | 
            ||
| 319 |                             ->setEmptyString('') | 
            ||
| 320 |                             ->setDescription(_t('Variation.PriceDescription', 'Does price modify or replace base price?')), | 
            ||
| 321 |                         CurrencyField::create('PriceModifier') | 
            ||
| 322 |                             ->setTitle(_t('Variation.PriceModifier', 'Price')) | 
            ||
| 323 |                             ->displayIf('PriceModifierAction')->isNotEmpty()->end(), | 
            ||
| 324 |                         CurrencyField::create('FinalPrice') | 
            ||
| 325 |                             ->setTitle('Final Modified Price') | 
            ||
| 326 |                             ->setDescription("Product's price is {$this->Product()->Price}") | 
            ||
| 327 | ->performDisabledTransformation()  | 
            ||
| 328 |                     )->setTitle('Price Modifications'), | 
            ||
| 329 | |||
| 330 | // Code Modifier Fields  | 
            ||
| 331 |                     //HeaderField::create('CodeHD', _t('Variation.CodeHD', 'Modify Code'), 4), | 
            ||
| 332 | FieldGroup::create(  | 
            ||
| 333 | DropdownField::create(  | 
            ||
| 334 | 'CodeModifierAction',  | 
            ||
| 335 |                             _t('Variation.CodeModifierAction', 'Code Modification Type'), | 
            ||
| 336 | [  | 
            ||
| 337 | 'Add' => _t(  | 
            ||
| 338 | 'Variation.CodeAdd',  | 
            ||
| 339 | 'Add to Base Code',  | 
            ||
| 340 | 'Add to code'  | 
            ||
| 341 | ),  | 
            ||
| 342 | 'Subtract' => _t(  | 
            ||
| 343 | 'Variation.CodeSubtract',  | 
            ||
| 344 | 'Subtract from Base Code',  | 
            ||
| 345 | 'Subtract from code'  | 
            ||
| 346 | ),  | 
            ||
| 347 |                                 'Set' => _t('Variation.CodeSet', 'Set as a new Code'), | 
            ||
| 348 | ]  | 
            ||
| 349 | )  | 
            ||
| 350 |                             ->setEmptyString('') | 
            ||
| 351 |                             ->setDescription(_t('Variation.CodeDescription', 'Does code modify or replace base code?')), | 
            ||
| 352 |                         TextField::create('CodeModifier') | 
            ||
| 353 |                             ->setTitle(_t('Variation.CodeModifier', 'Code')) | 
            ||
| 354 |                             ->displayIf('CodeModifierAction')->isNotEmpty()->end(), | 
            ||
| 355 |                         TextField::create('FinalCode') | 
            ||
| 356 |                             ->setTitle('Final Modified Code') | 
            ||
| 357 |                             ->setDescription("Product's code is {$this->Product()->Code}") | 
            ||
| 358 | ->performDisabledTransformation()  | 
            ||
| 359 |                     )->setTitle('Code Modification'), | 
            ||
| 360 | ]  | 
            ||
| 361 | );  | 
            ||
| 362 | |||
| 363 | // Images tab  | 
            ||
| 364 |             $images = SortableUploadField::create('Images') | 
            ||
| 365 |                 ->setSortColumn('SortOrder') | 
            ||
| 366 | ->setIsMultiUpload(true)  | 
            ||
| 367 |                 ->setAllowedExtensions($this->config()->get('allowed_images_extensions')) | 
            ||
| 368 |                 ->setFolderName('Uploads/Products/Images'); | 
            ||
| 369 | |||
| 370 |             $fields->addFieldsToTab('Root.Images', [ | 
            ||
| 371 | $images,  | 
            ||
| 372 | ]);  | 
            ||
| 373 | });  | 
            ||
| 374 | |||
| 375 | $fields = parent::getCMSFields();  | 
            ||
| 376 | |||
| 377 | $this->applyReadOnlyTransformations($fields);  | 
            ||
| 378 | |||
| 379 | return $fields;  | 
            ||
| 380 | }  | 
            ||
| 709 |