Field_Integer   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 65
Duplicated Lines 24.62 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 16
loc 65
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
B getOptions() 16 47 9

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * Part of the Joomla Framework Form Package
4
 *
5
 * @copyright  Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved.
6
 * @license    GNU General Public License version 2 or later; see LICENSE
7
 */
8
9
namespace Joomla\Form;
10
11
use Joomla\Form\Html\Select as HtmlSelect;
12
13
FormHelper::loadFieldClass('list');
14
15
/**
16
 * Form Field class for the Joomla Framework.
17
 * Provides a select list of integers with specified first, last and step values.
18
 *
19
 * @since       1.0
20
 * @deprecated  The joomla/form package is deprecated
21
 */
22
class Field_Integer extends Field_List
0 ignored issues
show
Deprecated Code introduced by
The class Joomla\Form\Field_List has been deprecated with message: The joomla/form package is deprecated

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
23
{
24
	/**
25
	 * The form field type.
26
	 *
27
	 * @var    string
28
	 * @since  1.0
29
	 */
30
	protected $type = 'Integer';
31
32
	/**
33
	 * Method to get the field options.
34
	 *
35
	 * @return  array  The field option objects.
36
	 *
37
	 * @since   1.0
38
	 */
39
	protected function getOptions()
40
	{
41
		$options = array();
42
43
		// Initialize some field attributes.
44
		$first = (int) $this->element['first'];
45
		$last = (int) $this->element['last'];
46
		$step = (int) $this->element['step'];
47
48
		// Sanity checks.
49
		if ($step == 0)
50
		{
51
			// Step of 0 will create an endless loop.
52
			return $options;
53
		}
54
		elseif ($first < $last && $step < 0)
55
		{
56
			// A negative step will never reach the last number.
57
			return $options;
58
		}
59
		elseif ($first > $last && $step > 0)
60
		{
61
			// A position step will never reach the last number.
62
			return $options;
63
		}
64 View Code Duplication
		elseif ($step < 0)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
65
		{
66
			// Build the options array backwards.
67
			for ($i = $first; $i >= $last; $i += $step)
68
			{
69
				$options[] = HtmlSelect::option($i);
70
			}
71
		}
72 View Code Duplication
		else
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
73
		{
74
			// Build the options array.
75
			for ($i = $first; $i <= $last; $i += $step)
76
			{
77
				$options[] = HtmlSelect::option($i);
78
			}
79
		}
80
81
		// Merge any additional options in the XML definition.
82
		$options = array_merge(parent::getOptions(), $options);
83
84
		return $options;
85
	}
86
}
87