Conditions | 4 |
Paths | 8 |
Total Lines | 122 |
Code Lines | 88 |
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 |
||
159 | public function getCMSFields() |
||
160 | { |
||
161 | $fields = parent::getCMSFields(); |
||
162 | |||
163 | // allow extensions of ProductPage to override the PreviewImage field description |
||
164 | $previewDescription = ($this->stat('customPreviewDescription')) ? $this->stat('customPreviewDescription') : _t('ProductPage.PreviewImageDescription', |
||
165 | 'Image used throughout site to represent this product'); |
||
166 | |||
167 | // Cateogry Dropdown field w/ add new |
||
168 | $source = function () { |
||
169 | return ProductCategory::get()->map()->toArray(); |
||
170 | }; |
||
171 | $catField = DropdownField::create('CategoryID', _t('ProductPage.Category', 'FoxyCart Category'), $source()) |
||
172 | ->setEmptyString('') |
||
173 | ->setDescription(_t( |
||
174 | 'ProductPage.CategoryDescription', |
||
175 | 'Required, must also exist in |
||
176 | <a href="https://admin.foxycart.com/admin.php?ThisAction=ManageProductCategories" target="_blank"> |
||
177 | FoxyCart Categories |
||
178 | </a>. |
||
179 | Used to set category specific options like shipping and taxes. Managed in |
||
180 | <a href="admin/settings"> |
||
181 | Settings > FoxyStripe > Categories |
||
182 | </a>' |
||
183 | )); |
||
184 | if (class_exists('QuickAddNewExtension')) { |
||
185 | $catField->useAddNew('ProductCategory', $source); |
||
186 | } |
||
187 | |||
188 | // Product Images gridfield |
||
189 | $config = GridFieldConfig_RelationEditor::create(); |
||
190 | $config->addComponent(new GridFieldOrderableRows('SortOrder')); |
||
191 | $prodImagesField = GridField::create( |
||
192 | 'ProductImages', |
||
193 | _t('ProductPage.ProductImages', 'Images'), |
||
194 | $this->ProductImages(), |
||
195 | $config |
||
196 | ); |
||
197 | |||
198 | // Product Options field |
||
199 | $config = GridFieldConfig_RelationEditor::create(); |
||
200 | $config->addComponent(new GridFieldOrderableRows('SortOrder')); |
||
201 | $products = $this->ProductOptions()->sort('SortOrder'); |
||
202 | $config->removeComponentsByType('GridFieldAddExistingAutocompleter'); |
||
203 | $prodOptField = GridField::create( |
||
204 | 'ProductOptions', |
||
205 | _t('ProductPage.ProductOptions', 'Options'), |
||
206 | $products, |
||
207 | $config |
||
208 | ); |
||
209 | |||
210 | // Details tab |
||
211 | $fields->addFieldsToTab('Root.Details', array( |
||
212 | HeaderField::create('DetailHD', 'Product Details', 2), |
||
213 | CheckboxField::create('Available') |
||
214 | ->setTitle(_t('ProductPage.Available', 'Available for purchase')) |
||
215 | ->setDescription(_t( |
||
216 | 'ProductPage.AvailableDescription', |
||
217 | 'If unchecked, will remove "Add to Cart" form and instead display "Currently unavailable"' |
||
218 | )), |
||
219 | TextField::create('Code') |
||
220 | ->setTitle(_t('ProductPage.Code', 'Product Code')) |
||
221 | ->setDescription(_t( |
||
222 | 'ProductPage.CodeDescription', |
||
223 | 'Required, must be unique. Product identifier used by FoxyCart in transactions' |
||
224 | )), |
||
225 | $catField, |
||
226 | CurrencyField::create('Price') |
||
227 | ->setTitle(_t('ProductPage.Price', 'Price')) |
||
228 | ->setDescription(_t( |
||
229 | 'ProductPage.PriceDescription', |
||
230 | 'Base price for this product. Can be modified using Product Options' |
||
231 | )), |
||
232 | NumericField::create('Weight') |
||
233 | ->setTitle(_t('ProductPage.Weight', 'Weight')) |
||
234 | ->setDescription(_t( |
||
235 | 'ProductPage.WeightDescription', |
||
236 | 'Base weight for this product in lbs. Can be modified using Product Options' |
||
237 | )), |
||
238 | CheckboxField::create('Featured') |
||
239 | ->setTitle(_t('ProductPage.Featured', 'Featured Product')), |
||
240 | TextField::create('ReceiptTitle') |
||
241 | ->setTitle(_t('ProductPage.ReceiptTitle', 'Product Title for Receipt')) |
||
242 | ->setDescription(_t( |
||
243 | 'ProductPage.ReceiptTitleDescription', 'Optional' |
||
244 | )) |
||
245 | )); |
||
246 | |||
247 | // Images tab |
||
248 | $fields->addFieldsToTab('Root.Images', array( |
||
249 | HeaderField::create('MainImageHD', _t('ProductPage.MainImageHD', 'Product Image'), 2), |
||
250 | UploadField::create('PreviewImage', '') |
||
251 | ->setDescription($previewDescription) |
||
252 | ->setFolderName('Uploads/Products') |
||
253 | ->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png')), |
||
254 | HeaderField::create('ProductImagesHD', _t('ProductPage.ProductImagesHD', 'Product Image Gallery'), 2), |
||
255 | $prodImagesField |
||
256 | ->setDescription(_t( |
||
257 | 'ProductPage.ProductImagesDescription', |
||
258 | 'Additional Product Images, shown in gallery on Product page' |
||
259 | )) |
||
260 | )); |
||
261 | |||
262 | // Options Tab |
||
263 | $fields->addFieldsToTab('Root.Options', array( |
||
264 | HeaderField::create('OptionsHD', _t('ProductPage.OptionsHD', 'Product Options'), 2), |
||
265 | LiteralField::create('OptionsDescrip', _t( |
||
266 | 'Page.OptionsDescrip', |
||
267 | '<p>Product Options allow products to be customized by attributes such as size or color. |
||
268 | Options can also modify the product\'s price, weight or code.</p>' |
||
269 | )), |
||
270 | $prodOptField |
||
271 | )); |
||
272 | |||
273 | if (FoxyCart::store_name_warning() !== null) { |
||
274 | $fields->addFieldToTab('Root.Main', LiteralField::create("StoreSubDomainHeaderWarning", _t( |
||
275 | 'ProductPage.StoreSubDomainHeaderWarning', |
||
276 | "<p class=\"message error\">Store sub-domain must be entered in the <a href=\"/admin/settings/\">site settings</a></p>" |
||
277 | )), 'Title'); |
||
278 | } |
||
279 | |||
280 | return $fields; |
||
281 | } |
||
414 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.