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