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