Field_Text   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 34
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 34
loc 34
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
B getInput() 15 15 7

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
/**
12
 * Form Field class for the Joomla Framework.
13
 * Supports a one line text field.
14
 *
15
 * @link        http://www.w3.org/TR/html-markup/input.text.html#input.text
16
 * @since       1.0
17
 * @deprecated  The joomla/form package is deprecated
18
 */
19 View Code Duplication
class Field_Text extends Field
0 ignored issues
show
Deprecated Code introduced by
The class Joomla\Form\Field 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...
Duplication introduced by
This class seems to be duplicated in 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...
20
{
21
	/**
22
	 * The form field type.
23
	 *
24
	 * @var    string
25
	 *
26
	 * @since  1.0
27
	 */
28
	protected $type = 'Text';
29
30
	/**
31
	 * Method to get the field input markup.
32
	 *
33
	 * @return  string  The field input markup.
34
	 *
35
	 * @since   1.0
36
	 */
37
	protected function getInput()
38
	{
39
		// Initialize some field attributes.
40
		$size = $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
41
		$maxLength = $this->element['maxlength'] ? ' maxlength="' . (int) $this->element['maxlength'] . '"' : '';
42
		$class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
43
		$readonly = ((string) $this->element['readonly'] == 'true') ? ' readonly="readonly"' : '';
44
		$disabled = ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : '';
45
46
		// Initialize JavaScript field attributes.
47
		$onchange = $this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : '';
48
49
		return '<input type="text" name="' . $this->name . '" id="' . $this->id . '"' . ' value="'
50
			. htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '"' . $class . $size . $disabled . $readonly . $onchange . $maxLength . '/>';
51
	}
52
}
53