Radio::isClicked()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
dl 9
loc 9
rs 9.2
c 0
b 0
f 0
cc 4
eloc 4
nc 3
nop 1
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 View Code Duplication
class Radio extends Common
0 ignored issues
show
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...
32
{
33
	/**
34
	 * the name of element
35
	 *
36
	 * @access private
37
	 * @var    string
38
	 */
39
	private $_sType = null;
40
	
41
	/**
42
	 * the label of element
43
	 *
44
	 * @access private
45
	 * @var    string
46
	 */
47
	private $_sLabel = null;
48
	
49
	/**
50
	 * the value of element
51
	 *
52
	 * @access private
53
	 * @var    string
54
	 */
55
	private $_sValue = null;
56
57
	/**
58
	 * the value of the checked element
59
	 *
60
	 * @access private
61
	 * @var    string
62
	 */
63
	private $_sValueChecked = null;
64
65
	/**
66
	 * constructor that it increment (static) for all use
67
	 *
68
	 * @access public
69
	 * @param  string $sName name
70
	 * @param  string $sLabel label of radio
71
	 * @param  string $sValue value of radio
72
	 * @param  string $sValueChecked value checked of radio
73
	 * @return \Venus\lib\Form\Input
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...
74
	 */
75
	public function __construct(string $sName, string $sLabel, string $sValue, string $sValueChecked = null)
76
	{
77
		$this->setName($sName);
78
		$this->setValue($sValue);
79
		$this->setValueChecked($sValueChecked);
80
		$this->setLabel($sLabel);
81
	}
82
83
	/**
84
	 * get the Value
85
	 *
86
	 * @access public
87
	 * @return string
88
	 */
89
	public function getValue() : string
90
	{
91
		return $this->_sValue;
92
	}
93
94
	/**
95
	 * set the Value
96
	 *
97
	 * @access public
98
	 * @param  string $sValue Value of input;
99
	 * @return Radio
100
	 */
101
	public function setValue(string $sValue) : Radio
102
	{
103
		$this->_sValue = $sValue;
104
		return $this;
105
	}
106
107
	/**
108
	 * get the Value Checked
109
	 *
110
	 * @access public
111
	 * @return string
112
	 */
113
	public function getValueChecked() : string
114
	{
115
		return $this->_sValueChecked;
116
	}
117
118
	/**
119
	 * set the Value Checked
120
	 *
121
	 * @access public
122
	 * @param  string $sValueChecked Value of input;
123
	 * @return Radio
124
	 */
125
	public function setValueChecked(string $sValueChecked) : Radio
126
	{
127
		$this->_sValueChecked = $sValueChecked;
128
		return $this;
129
	}
130
131
	/**
132
	 * get the Label
133
	 *
134
	 * @access public
135
	 * @return string
136
	 */
137
	public function getLabel() : string
138
	{
139
		return $this->_sLabel;
140
	}
141
142
	/**
143
	 * set the Label
144
	 *
145
	 * @access public
146
	 * @param  string $sLabel Label of input;
147
	 * @return Radio
148
	 */
149
	public function setLabel(string $sLabel) : Radio
150
	{
151
		$this->_sLabel = $sLabel;
152
		return $this;
153
	}
154
155
	/**
156
	 * if the button is clicked
157
	 *
158
	 * @access public
159
	 * @param  string $sType type of input;
160
	 * @return bool
161
	 */
162
	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...
163
	{
164
		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\Radio>.

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...
165
166
			if (isset($_POST[$this->getName()])) { return true; }
167
		}
168
169
		return false;
170
	}
171
172
	/**
173
	 * get the <html>
174
	 *
175
	 * @access public
176
	 * @return string
177
	 */
178
	public function fetch() : string
179
	{
180
		$sContent = '<input type="radio" name="'.$this->getName().'" value="'.$this->getValue().'"';
181
		
182
		if ($this->getValueChecked() == $this->getValue()) { $sContent .= ' checked="checked"'; }
183
		
184
		$sContent .= '/> '.$this->getLabel();
185
186
		return $sContent;
187
	}
188
}
189