Conditions | 3 |
Paths | 4 |
Total Lines | 105 |
Code Lines | 73 |
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 |
||
294 | protected function getFormFields($data) |
||
295 | { |
||
296 | $action = str_replace('amp;', '', $data['action']); |
||
297 | |||
298 | $option_text = array('yes' => $this->language->get('text_enabled'), 'no' => $this->language->get('text_disabled')); |
||
299 | |||
300 | $form = new AForm('form-cart', $action); |
||
301 | |||
302 | $form->addElement(new Arastta\Component\Form\Element\HTML('<legend>' . $this->language->get('text_general') . '</legend>')); |
||
303 | |||
304 | $name = array('value' => $data['name'], 'required' => 'required'); |
||
305 | $form->addElement(new Arastta\Component\Form\Element\Textbox($this->language->get('entry_name'), 'name', $name)); |
||
306 | |||
307 | $title = array('value' => $data['title'], 'required' => 'required'); |
||
308 | $form->addElement(new Arastta\Component\Form\Element\Textbox($this->language->get('entry_title'), 'title', $title)); |
||
309 | |||
310 | $show_title = array('value' => $data['show_title'], 'labelclass' => 'radio-inline'); |
||
311 | $form->addElement(new Arastta\Component\Form\Element\YesNo($this->language->get('entry_show_title'), 'show_title', $show_title, $option_text)); |
||
312 | |||
313 | $module_class = array('value' => $data['module_class']); |
||
314 | $form->addElement(new Arastta\Component\Form\Element\Textbox($this->language->get('entry_module_class'), 'module_class', $module_class)); |
||
315 | |||
316 | $module_column = array('value' => $data['module_column'], 'selected' => $data['module_column'], 'id' => 'input-module-column'); |
||
317 | $module_column_option = array('1' => '1', '2' => '2', '3' => '3', '4' => '4', '6' => '6'); |
||
318 | $form->addElement(new Arastta\Component\Form\Element\Select($this->language->get('entry_module_column'), 'module_column', $module_column_option, $module_column, $option_text)); |
||
|
|||
319 | |||
320 | $type = array('value' => $data['type'], 'selected' => $data['type'], 'id' => 'input-type'); |
||
321 | $type_option = array('all' => $this->language->get('text_all'), 'bestsellers' => $this->language->get('text_bestsellers'), 'featured' => $this->language->get('text_featured'), 'latest' => $this->language->get('text_latest'), 'special' => $this->language->get('text_special')); |
||
322 | $form->addElement(new Arastta\Component\Form\Element\Select($this->language->get('entry_type'), 'type', $type_option, $type)); |
||
323 | |||
324 | $html = '<div class="form-group">'; |
||
325 | $html .= ' <label class="col-sm-2 control-label" for="input-category"><span data-toggle="tooltip" title="' . $this->language->get('help_category') . '">' . $this->language->get('entry_category') . '</span></label>'; |
||
326 | $html .= ' <div class="col-sm-10">'; |
||
327 | $html .= ' <input type="text" name="category" value="" placeholder="' . $this->language->get('entry_category') . '" id="input-category" class="form-control" />'; |
||
328 | $html .= ' <div id="categories" class="well well-sm" style="height: 150px; overflow: auto;">'; |
||
329 | foreach ($data['categories'] as $category) { |
||
330 | $html .= ' <div id="categories' . $category['category_id'] . '"><i class="fa fa-minus-circle"></i> '. $category['name']; |
||
331 | $html .= ' <input type="hidden" name="category[]" value="' . $category['category_id'] . '" />'; |
||
332 | $html .= ' </div>'; |
||
333 | } |
||
334 | $html .= ' </div>'; |
||
335 | $html .= ' </div>'; |
||
336 | $html .= '</div>'; |
||
337 | |||
338 | $form->addElement(new Arastta\Component\Form\Element\HTML($html)); |
||
339 | |||
340 | $html = '<div class="form-group">'; |
||
341 | $html .= ' <label class="col-sm-2 control-label" for="input-product"><span data-toggle="tooltip" title="' . $this->language->get('help_product') . '">' . $this->language->get('entry_product') . '</span></label>'; |
||
342 | $html .= ' <div class="col-sm-10">'; |
||
343 | $html .= ' <input type="text" name="product" value="" placeholder="' . $this->language->get('entry_product') . '" id="input-product" class="form-control" />'; |
||
344 | $html .= ' <div id="featured-product" class="well well-sm" style="height: 150px; overflow: auto;">'; |
||
345 | foreach ($data['products'] as $product) { |
||
346 | $html .= ' <div id="featured-product' . $product['product_id'] . '"><i class="fa fa-minus-circle"></i> '. $product['name']; |
||
347 | $html .= ' <input type="hidden" name="product[]" value="' . $product['product_id'] . '" />'; |
||
348 | $html .= ' </div>'; |
||
349 | } |
||
350 | $html .= ' </div>'; |
||
351 | $html .= ' </div>'; |
||
352 | $html .= '</div>'; |
||
353 | |||
354 | $form->addElement(new Arastta\Component\Form\Element\HTML($html)); |
||
355 | |||
356 | $random_product = array('value' => $data['random_product'], 'labelclass' => 'radio-inline'); |
||
357 | $form->addElement(new Arastta\Component\Form\Element\YesNo($this->language->get('entry_random_product'), 'random_product', $random_product, $option_text)); |
||
358 | |||
359 | $limit = array('value' => $data['limit'], 'required' => 'required'); |
||
360 | $form->addElement(new Arastta\Component\Form\Element\Textbox($this->language->get('entry_limit'), 'limit', $limit)); |
||
361 | |||
362 | $width = array('value' => $data['width'], 'required' => 'required'); |
||
363 | $form->addElement(new Arastta\Component\Form\Element\Textbox($this->language->get('entry_width'), 'width', $width)); |
||
364 | |||
365 | $height = array('value' => $data['height'], 'required' => 'required'); |
||
366 | $form->addElement(new Arastta\Component\Form\Element\Textbox($this->language->get('entry_height'), 'height', $height)); |
||
367 | |||
368 | $status = array('value' => $data['status'], 'labelclass' => 'radio-inline'); |
||
369 | $form->addElement(new Arastta\Component\Form\Element\YesNo($this->language->get('entry_status'), 'status', $status, $option_text)); |
||
370 | |||
371 | $form->addElement(new Arastta\Component\Form\Element\HTML('<legend>' . $this->language->get('text_view') . '</legend>')); |
||
372 | |||
373 | $product_image = array('value' => $data['product_image'], 'labelclass' => 'radio-inline'); |
||
374 | $form->addElement(new Arastta\Component\Form\Element\YesNo($this->language->get('entry_image'), 'product_image', $product_image, $option_text)); |
||
375 | |||
376 | $product_name = array('value' => $data['product_name'], 'labelclass' => 'radio-inline'); |
||
377 | $form->addElement(new Arastta\Component\Form\Element\YesNo($this->language->get('entry_pname'), 'product_name', $product_name, $option_text)); |
||
378 | |||
379 | $product_description = array('value' => $data['product_description'], 'labelclass' => 'radio-inline'); |
||
380 | $form->addElement(new Arastta\Component\Form\Element\YesNo($this->language->get('entry_pdescription'), 'product_description', $product_description, $option_text)); |
||
381 | |||
382 | $product_rating = array('value' => $data['product_rating'], 'labelclass' => 'radio-inline'); |
||
383 | $form->addElement(new Arastta\Component\Form\Element\YesNo($this->language->get('entry_rating'), 'product_rating', $product_rating, $option_text)); |
||
384 | |||
385 | $product_price = array('value' => $data['product_price'], 'labelclass' => 'radio-inline'); |
||
386 | $form->addElement(new Arastta\Component\Form\Element\YesNo($this->language->get('entry_price'), 'product_price', $product_price, $option_text)); |
||
387 | |||
388 | $add_to_cart = array('value' => $data['add_to_cart'], 'labelclass' => 'radio-inline'); |
||
389 | $form->addElement(new Arastta\Component\Form\Element\YesNo($this->language->get('entry_add_to_cart'), 'add_to_cart', $add_to_cart, $option_text)); |
||
390 | |||
391 | $wish_list = array('value' => $data['wish_list'], 'labelclass' => 'radio-inline'); |
||
392 | $form->addElement(new Arastta\Component\Form\Element\YesNo($this->language->get('entry_wish_list'), 'wish_list', $wish_list, $option_text)); |
||
393 | |||
394 | $compare = array('value' => $data['compare'], 'labelclass' => 'radio-inline'); |
||
395 | $form->addElement(new Arastta\Component\Form\Element\YesNo($this->language->get('entry_compare'), 'compare', $compare, $option_text)); |
||
396 | |||
397 | return $form->render(true); |
||
398 | } |
||
399 | |||
413 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.