| Conditions | 1 |
| Paths | 1 |
| Total Lines | 90 |
| Code Lines | 62 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 65 | public function getCMSFields() |
||
| 66 | { |
||
| 67 | $this->beforeUpdateCMSFields(function (FieldList $fields) { |
||
| 68 | |||
| 69 | $fields->removeByName([ |
||
| 70 | 'Types', |
||
| 71 | |||
| 72 | ]); |
||
| 73 | |||
| 74 | $fields->addFieldsToTab('Root.Main', array( |
||
| 75 | CheckboxField::create('ManyMany[Available]', 'Available for purchase'), |
||
| 76 | |||
| 77 | // Weight Modifier Fields |
||
| 78 | HeaderField::create('WeightHD', _t('OptionItem.WeightHD', 'Modify Weight'), 4), |
||
| 79 | TextField::create("ManyMany[WeightModifier]") |
||
| 80 | ->setTitle(_t('OptionItem.WeightModifier', 'Weight')), |
||
| 81 | DropdownField::create( |
||
| 82 | 'ManyMany[WeightModifierAction]', |
||
| 83 | _t('OptionItem.WeightModifierAction', 'Weight Modification'), |
||
| 84 | array( |
||
| 85 | 'Add' => _t( |
||
| 86 | 'OptionItem.WeightAdd', |
||
| 87 | 'Add to Base Weight', |
||
| 88 | 'Add to weight' |
||
| 89 | ), |
||
| 90 | 'Subtract' => _t( |
||
| 91 | 'OptionItem.WeightSubtract', |
||
| 92 | 'Subtract from Base Weight', |
||
| 93 | 'Subtract from weight' |
||
| 94 | ), |
||
| 95 | 'Set' => _t('OptionItem.WeightSet', 'Set as a new Weight'), |
||
| 96 | ) |
||
| 97 | ) |
||
| 98 | ->setEmptyString('') |
||
| 99 | ->setDescription(_t( |
||
| 100 | 'OptionItem.WeightDescription', |
||
| 101 | 'Does weight modify or replace base weight?' |
||
| 102 | )), |
||
| 103 | |||
| 104 | // Price Modifier FIelds |
||
| 105 | HeaderField::create('PriceHD', _t('OptionItem.PriceHD', 'Modify Price'), 4), |
||
| 106 | CurrencyField::create('ManyMany[PriceModifier]') |
||
| 107 | ->setTitle(_t('OptionItem.PriceModifier', 'Price')), |
||
| 108 | DropdownField::create( |
||
| 109 | 'ManyMany[PriceModifierAction]', |
||
| 110 | _t('OptionItem.PriceModifierAction', 'Price Modification'), |
||
| 111 | array( |
||
| 112 | 'Add' => _t( |
||
| 113 | 'OptionItem.PriceAdd', |
||
| 114 | 'Add to Base Price', |
||
| 115 | 'Add to price' |
||
| 116 | ), |
||
| 117 | 'Subtract' => _t( |
||
| 118 | 'OptionItem.PriceSubtract', |
||
| 119 | 'Subtract from Base Price', |
||
| 120 | 'Subtract from price' |
||
| 121 | ), |
||
| 122 | 'Set' => _t('OptionItem.PriceSet', 'Set as a new Price'), |
||
| 123 | ) |
||
| 124 | ) |
||
| 125 | ->setEmptyString('') |
||
| 126 | ->setDescription(_t('OptionItem.PriceDescription', 'Does price modify or replace base price?')), |
||
| 127 | |||
| 128 | // Code Modifier Fields |
||
| 129 | HeaderField::create('CodeHD', _t('OptionItem.CodeHD', 'Modify Code'), 4), |
||
| 130 | TextField::create('ManyMany[CodeModifier]') |
||
| 131 | ->setTitle(_t('OptionItem.CodeModifier', 'Code')), |
||
| 132 | DropdownField::create( |
||
| 133 | 'ManyMany[CodeModifierAction]', |
||
| 134 | _t('OptionItem.CodeModifierAction', 'Code Modification'), |
||
| 135 | array( |
||
| 136 | 'Add' => _t( |
||
| 137 | 'OptionItem.CodeAdd', |
||
| 138 | 'Add to Base Code', |
||
| 139 | 'Add to code' |
||
| 140 | ), |
||
| 141 | 'Subtract' => _t( |
||
| 142 | 'OptionItem.CodeSubtract', |
||
| 143 | 'Subtract from Base Code', |
||
| 144 | 'Subtract from code' |
||
| 145 | ), |
||
| 146 | 'Set' => _t('OptionItem.CodeSet', 'Set as a new Code'), |
||
| 147 | ) |
||
| 148 | ) |
||
| 149 | ->setEmptyString('') |
||
| 150 | ->setDescription(_t('OptionItem.CodeDescription', 'Does code modify or replace base code?')), |
||
| 151 | )); |
||
| 152 | }); |
||
| 153 | |||
| 154 | return parent::getCMSFields(); |
||
| 155 | } |
||
| 290 |