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