Passed
Push — master ( 9c6b4e...07b0df )
by judicael
03:29
created

bundles/lib/Form/Checkbox.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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 Checkbox extends Common
0 ignored issues
show
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    array
62
	 */
63
	private $_aValuesChecked = 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 checkbox
71
	 * @param  string $sValue value of checkbox
72
	 * @param  array $aValuesChecked value checked of checkbox
73
	 */
74
	public function __construct(string $sName, string $sLabel, string $sValue, array $aValuesChecked = null)
75
	{
76
		$this->setName($sName);
77
		$this->setValue($sValue);
78
		$this->setValuesChecked($aValuesChecked);
79
		$this->setLabel($sLabel);
80
	}
81
82
	/**
83
	 * get the Value
84
	 *
85
	 * @access public
86
	 * @return string
87
	 */
88
	public function getValue() : string
89
	{
90
		return $this->_sValue;
91
	}
92
93
	/**
94
	 * set the Value
95
	 *
96
	 * @access public
97
	 * @param  string $sValue Value of input;
98
	 * @return Checkbox
99
	 */
100
	public function setValue(string $sValue) : Checkbox
101
	{
102
		$this->_sValue = $sValue;
103
		return $this;
104
	}
105
106
	/**
107
	 * get the Value Checked
108
	 *
109
	 * @access public
110
	 * @return array
111
	 */
112
	public function getValuesChecked() : array
113
	{
114
		return $this->_aValuesChecked;
115
	}
116
117
	/**
118
	 * set the Value Checked
119
	 *
120
	 * @access public
121
	 * @param  array $aValuesChecked Values of input;
122
	 * @return Checkbox
123
	 */
124
	public function setValuesChecked(array $aValuesChecked) : Checkbox
125
	{
126
		$this->_aValuesChecked = $aValuesChecked;
127
		return $this;
128
	}
129
130
	/**
131
	 * get the Label
132
	 *
133
	 * @access public
134
	 * @return string
135
	 */
136
	public function getLabel() : string
137
	{
138
		return $this->_sLabel;
139
	}
140
141
	/**
142
	 * set the Label
143
	 *
144
	 * @access public
145
	 * @param  string $sLabel Label of input;
146
	 * @return Checkbox
147
	 */
148
	public function setLabel(string $sLabel) : Checkbox
149
	{
150
		$this->_sLabel = $sLabel;
151
		return $this;
152
	}
153
154
	/**
155
	 * if the button is clicked
156
	 *
157
	 * @access public
158
	 * @param  string $sType type of input;
159
	 * @return bool
160
	 */
161
	public function isClicked(string $sType) : bool
162
	{
163
		if ($this->getType() === 'submit' || $this->getType() === 'button') {
164
165
			if (isset($_POST[$this->getName()])) { return true; }
166
		}
167
168
		return false;
169
	}
170
171
	/**
172
	 * get the <html>
173
	 *
174
	 * @access public
175
	 * @return string
176
	 */
177
	public function fetch() : string
178
	{
179
		$sContent = '<input type="checkbox" name="'.$this->getName().'[]" value="'.$this->getValue().'"';
180
181
		if (in_array($this->getValue(), $this->getValuesChecked())) { $sContent .= ' checked="checked"'; }
182
		
183
		$sContent .= '/> '.$this->getLabel();
184
185
		return $sContent;
186
	}
187
}
188