Textarea   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 125
Duplicated Lines 6.4 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 1
dl 8
loc 125
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 8 8 2
A getValue() 0 4 1
A setValue() 0 5 1
A getLabel() 0 4 1
A setLabel() 0 5 1
A isClicked() 0 9 4
A fetch() 0 17 3

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
/**
4
 * Manage Form
5
 *
6
 * @category  	lib
7
 * @package		lib\Form
8
 * @author    	Judicaël Paquet <[email protected]>
9
 * @copyright 	Copyright (c) 2013-2014 PAQUET Judicaël FR Inc. (https://github.com/las93)
10
 * @license   	https://github.com/las93/venus2/blob/master/LICENSE.md Tout droit réservé à PAQUET Judicaël
11
 * @version   	Release: 1.0.0
12
 * @filesource	https://github.com/las93/venus2
13
 * @link      	https://github.com/las93
14
 * @since     	1.0
15
 */
16
namespace Venus\lib\Form;
17
18
/**
19
 * This class manage the Form
20
 *
21
 * @category  	lib
22
 * @package		lib\Form
23
 * @author    	Judicaël Paquet <[email protected]>
24
 * @copyright 	Copyright (c) 2013-2014 PAQUET Judicaël FR Inc. (https://github.com/las93)
25
 * @license   	https://github.com/las93/venus2/blob/master/LICENSE.md Tout droit réservé à PAQUET Judicaël
26
 * @version   	Release: 1.0.0
27
 * @filesource	https://github.com/las93/venus2
28
 * @link      	https://github.com/las93
29
 * @since     	1.0
30
 */
31
class Textarea extends Common
32
{
33
	/**
34
	 * the label of element
35
	 *
36
	 * @access private
37
	 * @var    string
38
	 */
39
	private $_sLabel = null;
40
	
41
	/**
42
	 * the value of element
43
	 *
44
	 * @access private
45
	 * @var    string
46
	 */
47
	private $_sValue = null;
48
49
	/**
50
	 * constructor that it increment (static) for all use
51
	 *
52
	 * @access public
53
	 * @param  string $sName name
54
	 * @param  string $sLabel label of textarea
55
	 * @param  string $sValue value of textarea
56
	 * @return \Venus\lib\Form\Textarea
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
57
	 */
58 View Code Duplication
	public function __construct(string $sName, string $sLabel = null, string $sValue = null)
0 ignored issues
show
Duplication introduced by
This method 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...
59
	{
60
		$this->setName($sName);
61
		$this->setValue($sValue);
62
63
		if ($sLabel !== null) { $this->setLabel($sLabel); }
64
		else { $this->setLabel($sName); }
65
	}
66
67
	/**
68
	 * get the Value
69
	 *
70
	 * @access public
71
	 * @return string
72
	 */
73
	public function getValue() : string
74
	{
75
		return $this->_sValue;
76
	}
77
78
	/**
79
	 * set the Value
80
	 *
81
	 * @access public
82
	 * @param  string $sValue Value of input;
83
	 * @return \Venus\lib\Form\Textarea
84
	 */
85
	public function setValue(string $sValue) : Textarea
86
	{
87
		$this->_sValue = $sValue;
88
		return $this;
89
	}
90
91
	/**
92
	 * get the Label
93
	 *
94
	 * @access public
95
	 * @return string
96
	 */
97
	public function getLabel() : string
98
	{
99
		return $this->_sLabel;
100
	}
101
102
	/**
103
	 * set the Label
104
	 *
105
	 * @access public
106
	 * @param  string $sLabel Label of input;
107
	 * @return \Venus\lib\Form\Textarea
108
	 */
109
	public function setLabel(string $sLabel) : Textarea
110
	{
111
		$this->_sLabel = $sLabel;
112
		return $this;
113
	}
114
115
	/**
116
	 * if the button is clicked
117
	 *
118
	 * @access public
119
	 * @param  string $sType type of input;
120
	 * @return bool
121
	 */
122
	public function isClicked(string $sType) : bool
0 ignored issues
show
Unused Code introduced by
The parameter $sType is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
123
	{
124
		if ($this->getType() === 'submit' || $this->getType() === 'button') {
0 ignored issues
show
Bug introduced by
The method getType() does not seem to exist on object<Venus\lib\Form\Textarea>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
125
126
			if (isset($_POST[$this->getName()])) { return true; }
127
		}
128
129
		return false;
130
	}
131
132
	/**
133
	 * get the <html>
134
	 *
135
	 * @access public
136
	 * @return string
137
	 */
138
	public function fetch() : string
139
	{
140
		$sContent = '';
141
142
		if ($this->getLabel()) {
143
144
			$sContent .= '<label>'.$this->getLabel().'</label> ';
145
		}
146
147
		$sContent .= '<textarea name="'.$this->getName().'">';
148
		
149
		if ($this->getValue() !== null) { $sContent .= $this->getValue(); }
150
		
151
		$sContent .= '</textarea>';
152
153
		return $sContent;
154
	}
155
}
156