Field_Spacer   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 94
Duplicated Lines 8.51 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 8
loc 94
rs 10
c 0
b 0
f 0
wmc 11
lcom 1
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getInput() 0 4 1
B getLabel() 8 49 9
A getTitle() 0 4 1

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\Language\Text;
12
13
/**
14
 * Form Field class for the Joomla Framework.
15
 * Provides spacer markup to be used in form layouts.
16
 *
17
 * @since       1.0
18
 * @deprecated  The joomla/form package is deprecated
19
 */
20
class Field_Spacer 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...
21
{
22
	/**
23
	 * The form field type.
24
	 *
25
	 * @var    string
26
	 * @since  1.0
27
	 */
28
	protected $type = 'Spacer';
29
30
	/**
31
	 * Method to get the field input markup for a spacer.
32
	 * The spacer does not have accept input.
33
	 *
34
	 * @return  string  The field input markup.
35
	 *
36
	 * @since   1.0
37
	 */
38
	protected function getInput()
39
	{
40
		return ' ';
41
	}
42
43
	/**
44
	 * Method to get the field label markup for a spacer.
45
	 * Use the label text or name from the XML element as the spacer or
46
	 * Use a hr="true" to automatically generate plain hr markup
47
	 *
48
	 * @return  string  The field label markup.
49
	 *
50
	 * @since   1.0
51
	 */
52
	protected function getLabel()
53
	{
54
		$html = array();
55
		$class = $this->element['class'] ? (string) $this->element['class'] : '';
56
57
		$html[] = '<span class="spacer">';
58
		$html[] = '<span class="before"></span>';
59
		$html[] = '<span class="' . $class . '">';
60
61
		if ((string) $this->element['hr'] == 'true')
62
		{
63
			$html[] = '<hr class="' . $class . '" />';
64
		}
65
		else
66
		{
67
			$label = '';
68
69
			// Get the label text from the XML element, defaulting to the element name.
70
			$text = $this->element['label'] ? (string) $this->element['label'] : (string) $this->element['name'];
71
			$text = $this->translateLabel ? Text::_($text) : $text;
0 ignored issues
show
Deprecated Code introduced by
The method Joomla\Language\Text::_() has been deprecated with message: 2.0 Will be replaced with a `translate` method.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

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

Loading history...
72
73
			// Build the class for the label.
74
			$class = !empty($this->description) ? 'hasTip' : '';
75
			$class = $this->required == true ? $class . ' required' : $class;
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
76
77
			// Add the opening label tag and main attributes attributes.
78
			$label .= '<label id="' . $this->id . '-lbl" class="' . $class . '"';
79
80
			// If a description is specified, use it to build a tooltip.
81 View Code Duplication
			if (!empty($this->description))
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...
82
			{
83
				$label .= ' title="'
84
					. htmlspecialchars(
85
					trim($text, ':') . '::' . ($this->translateDescription ? Text::_($this->description) : $this->description),
0 ignored issues
show
Deprecated Code introduced by
The method Joomla\Language\Text::_() has been deprecated with message: 2.0 Will be replaced with a `translate` method.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

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

Loading history...
86
					ENT_COMPAT, 'UTF-8'
87
				) . '"';
88
			}
89
90
			// Add the label text and closing tag.
91
			$label .= '>' . $text . '</label>';
92
			$html[] = $label;
93
		}
94
95
		$html[] = '</span>';
96
		$html[] = '<span class="after"></span>';
97
		$html[] = '</span>';
98
99
		return implode('', $html);
100
	}
101
102
	/**
103
	 * Method to get the field title.
104
	 *
105
	 * @return  string  The field title.
106
	 *
107
	 * @since   1.0
108
	 */
109
	protected function getTitle()
110
	{
111
		return $this->getLabel();
112
	}
113
}
114