Conditions | 12 |
Paths | 482 |
Total Lines | 109 |
Code Lines | 63 |
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 |
||
145 | protected function getProductFields(FieldList $fields): FieldList |
||
146 | { |
||
147 | $hiddenTitle = ($this->product->ReceiptTitle) ? |
||
148 | htmlspecialchars($this->product->ReceiptTitle) : |
||
149 | htmlspecialchars($this->product->Title); |
||
150 | $code = $this->product->Code; |
||
151 | |||
152 | if ($this->product->getIsAvailable()) { |
||
153 | $fields->push( |
||
154 | HiddenField::create('name') |
||
155 | ->setValue( |
||
156 | self::getGeneratedValue($code, 'name', $hiddenTitle, 'value') |
||
157 | ) |
||
158 | ); |
||
159 | |||
160 | $fields->push( |
||
161 | HiddenField::create('category') |
||
162 | ->setValue( |
||
163 | self::getGeneratedValue($code, 'category', $this->product->FoxyCategory()->Code, 'value') |
||
164 | ) |
||
165 | ); |
||
166 | |||
167 | $fields->push( |
||
168 | HiddenField::create('code') |
||
169 | ->setValue( |
||
170 | self::getGeneratedValue($code, 'code', $this->product->Code, 'value') |
||
171 | ) |
||
172 | ); |
||
173 | |||
174 | $fields->push( |
||
175 | HiddenField::create('product_id') |
||
176 | ->setValue( |
||
177 | self::getGeneratedValue($code, 'product_id', $this->product->ID, 'value') |
||
178 | ) |
||
179 | ->setName('h:product_id') |
||
180 | ); |
||
181 | |||
182 | $fields->push( |
||
183 | HiddenField::create('price') |
||
184 | ->setValue( |
||
185 | self::getGeneratedValue($code, 'price', $this->product->Price, 'value') |
||
186 | ) |
||
187 | ); |
||
188 | |||
189 | if ($this->product->hasMethod('AbsoluteLink')) { |
||
190 | $fields->push( |
||
191 | HiddenField::create('url') |
||
192 | ->setValue( |
||
193 | self::getGeneratedValue($code, 'url', $this->product->AbsoluteLink(), 'value') |
||
194 | ) |
||
195 | ); |
||
196 | } |
||
197 | |||
198 | if ($this->product instanceof ShippableProduct) { |
||
199 | if ($this->product->Weight > 0) { |
||
200 | $fields->push( |
||
201 | HiddenField::create('weight') |
||
202 | ->setValue( |
||
203 | self::getGeneratedValue($code, 'weight', $this->product->Weight, 'value') |
||
204 | ) |
||
205 | ); |
||
206 | } |
||
207 | } |
||
208 | |||
209 | $image = null; |
||
210 | if ($this->product->hasMethod('getImage')) { |
||
211 | if ($this->product->getImage()) { |
||
212 | $image = $this->product->getImage()->CMSThumbnail()->absoluteURL; |
||
213 | } |
||
214 | if ($image) { |
||
215 | $fields->push( |
||
216 | HiddenField::create('image') |
||
217 | ->setValue( |
||
218 | self::getGeneratedValue($code, 'image', $image, 'value') |
||
219 | ) |
||
220 | ); |
||
221 | } |
||
222 | } |
||
223 | |||
224 | if ($this->product->QuantityMax > 0) { |
||
225 | $fields->push( |
||
226 | HiddenField::create('quantity_max') |
||
227 | ->setValue(self::getGeneratedValue($code, 'quantity_max', $this->product->QuantityMax, 'value')) |
||
228 | ); |
||
229 | } |
||
230 | |||
231 | if ($variationsField = $this->getProductVariations()) { |
||
232 | $fields->push($variationsField); |
||
233 | } |
||
234 | |||
235 | if ($this->product->QuantityMax != 1) { |
||
236 | $fields->push(QuantityField::create('x:visibleQuantity')->setTitle('Quantity')->setValue(1)); |
||
237 | } |
||
238 | $fields->push( |
||
239 | HiddenField::create('quantity') |
||
240 | ->setValue( |
||
241 | self::getGeneratedValue($code, 'quantity', 1, 'value') |
||
242 | ) |
||
243 | ); |
||
244 | |||
245 | $fields->push( |
||
246 | HeaderField::create('submitPrice', '$' . $this->product->Price, 4) |
||
247 | ->addExtraClass('submit-price') |
||
248 | ); |
||
249 | } |
||
250 | |||
251 | $this->extend('updateProductFields', $fields); |
||
252 | |||
253 | return $fields; |
||
254 | } |
||
372 |