| Conditions | 2 |
| Paths | 1 |
| Total Lines | 100 |
| Code Lines | 68 |
| 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 |
||
| 81 | public function getCMSFields() |
||
| 82 | { |
||
| 83 | $this->beforeUpdateCMSFields(function (FieldList $fields) { |
||
| 84 | if ($this->exists()) { |
||
| 85 | $fields->addFieldToTab( |
||
| 86 | 'Root.Main', |
||
| 87 | ReadonlyField::create('ManyMany[OptionModifierKey]') |
||
| 88 | ->setTitle(_t('OptionItem.ModifierKey', 'Modifier Key')) |
||
| 89 | ); |
||
| 90 | } |
||
| 91 | |||
| 92 | $fields->addFieldsToTab('Root.Main', [ |
||
| 93 | CheckboxField::create('ManyMany[Available]', 'Available for purchase'), |
||
| 94 | |||
| 95 | DropdownField::create('ManyMany[Type]', 'Option Type', OptionType::get()->map()) |
||
| 96 | ->setEmptyString(''), |
||
| 97 | |||
| 98 | // Weight Modifier Fields |
||
| 99 | HeaderField::create('WeightHD', _t('OptionItem.WeightHD', 'Modify Weight'), 4), |
||
| 100 | NumericField::create("ManyMany[WeightModifier]") |
||
| 101 | ->setTitle(_t('OptionItem.WeightModifier', 'Weight')) |
||
| 102 | ->setScale(3) |
||
| 103 | ->setDescription(_t( |
||
| 104 | 'OptionItem.WeightDescription', |
||
| 105 | 'Only supports up to 3 decimal places' |
||
| 106 | )), |
||
| 107 | DropdownField::create( |
||
| 108 | 'ManyMany[WeightModifierAction]', |
||
| 109 | _t('OptionItem.WeightModifierAction', 'Weight Modification'), |
||
| 110 | [ |
||
| 111 | 'Add' => _t( |
||
| 112 | 'OptionItem.WeightAdd', |
||
| 113 | 'Add to Base Weight', |
||
| 114 | 'Add to weight' |
||
| 115 | ), |
||
| 116 | 'Subtract' => _t( |
||
| 117 | 'OptionItem.WeightSubtract', |
||
| 118 | 'Subtract from Base Weight', |
||
| 119 | 'Subtract from weight' |
||
| 120 | ), |
||
| 121 | 'Set' => _t('OptionItem.WeightSet', 'Set as a new Weight'), |
||
| 122 | ] |
||
| 123 | ) |
||
| 124 | ->setEmptyString('') |
||
| 125 | ->setDescription(_t( |
||
| 126 | 'OptionItem.WeightDescription', |
||
| 127 | 'Does weight modify or replace base weight?' |
||
| 128 | )), |
||
| 129 | |||
| 130 | // Price Modifier Fields |
||
| 131 | HeaderField::create('PriceHD', _t('OptionItem.PriceHD', 'Modify Price'), 4), |
||
| 132 | CurrencyField::create('ManyMany[PriceModifier]') |
||
| 133 | ->setTitle(_t('OptionItem.PriceModifier', 'Price')), |
||
| 134 | DropdownField::create( |
||
| 135 | 'ManyMany[PriceModifierAction]', |
||
| 136 | _t('OptionItem.PriceModifierAction', 'Price Modification'), |
||
| 137 | [ |
||
| 138 | 'Add' => _t( |
||
| 139 | 'OptionItem.PriceAdd', |
||
| 140 | 'Add to Base Price', |
||
| 141 | 'Add to price' |
||
| 142 | ), |
||
| 143 | 'Subtract' => _t( |
||
| 144 | 'OptionItem.PriceSubtract', |
||
| 145 | 'Subtract from Base Price', |
||
| 146 | 'Subtract from price' |
||
| 147 | ), |
||
| 148 | 'Set' => _t('OptionItem.PriceSet', 'Set as a new Price'), |
||
| 149 | ] |
||
| 150 | ) |
||
| 151 | ->setEmptyString('') |
||
| 152 | ->setDescription(_t('OptionItem.PriceDescription', 'Does price modify or replace base price?')), |
||
| 153 | |||
| 154 | // Code Modifier Fields |
||
| 155 | HeaderField::create('CodeHD', _t('OptionItem.CodeHD', 'Modify Code'), 4), |
||
| 156 | TextField::create('ManyMany[CodeModifier]') |
||
| 157 | ->setTitle(_t('OptionItem.CodeModifier', 'Code')), |
||
| 158 | DropdownField::create( |
||
| 159 | 'ManyMany[CodeModifierAction]', |
||
| 160 | _t('OptionItem.CodeModifierAction', 'Code Modification'), |
||
| 161 | [ |
||
| 162 | 'Add' => _t( |
||
| 163 | 'OptionItem.CodeAdd', |
||
| 164 | 'Add to Base Code', |
||
| 165 | 'Add to code' |
||
| 166 | ), |
||
| 167 | 'Subtract' => _t( |
||
| 168 | 'OptionItem.CodeSubtract', |
||
| 169 | 'Subtract from Base Code', |
||
| 170 | 'Subtract from code' |
||
| 171 | ), |
||
| 172 | 'Set' => _t('OptionItem.CodeSet', 'Set as a new Code'), |
||
| 173 | ] |
||
| 174 | ) |
||
| 175 | ->setEmptyString('') |
||
| 176 | ->setDescription(_t('OptionItem.CodeDescription', 'Does code modify or replace base code?')), |
||
| 177 | ]); |
||
| 178 | }); |
||
| 179 | |||
| 180 | return parent::getCMSFields(); |
||
| 181 | } |
||
| 399 |