Input   A
last analyzed

Complexity

Total Complexity 29

Size/Duplication

Total Lines 161
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 29
lcom 1
cbo 1
dl 0
loc 161
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A getType() 0 4 1
A setType() 0 5 1
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
C fetch() 0 21 17
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 Input extends Common
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
     * constructor that it increment (static) for all use
59
     *
60
     * @access public
61
     * @param  string $sName name
62
     * @param  string $sType type of input
63
     * @param  string $sLabel label of input
64
     * @param  string $sValue value of input
65
     */
66
    public function __construct(string $sName, string $sType, string $sLabel = null, string $sValue = null)
67
    {
68
        $this->setName($sName);
69
        $this->setType($sType);
70
        $this->setValue($sValue);
71
72
        if ($sLabel !== null) { $this->setLabel($sLabel); } else { $this->setLabel($sName); }
73
    }
74
75
    /**
76
     * get the type
77
     *
78
     * @access public
79
     * @return string
80
     */
81
    public function getType() : string
82
    {
83
        return $this->_sType;
84
    }
85
86
    /**
87
     * set the type
88
     *
89
     * @access public
90
     * @param  string $sType type of input;
91
     * @return \Venus\lib\Form\Input
92
     */
93
    public function setType(string $sType) : Input
94
    {
95
        $this->_sType = $sType;
96
        return $this;
97
    }
98
99
    /**
100
     * get the Value
101
     *
102
     * @access public
103
     * @return string
104
     */
105
    public function getValue() : string
106
    {
107
        return $this->_sValue;
108
    }
109
110
    /**
111
     * set the Value
112
     *
113
     * @access public
114
     * @param  string $sValue Value of input;
115
     * @return \Venus\lib\Form\Input
116
     */
117
    public function setValue(string $sValue) : Input
118
    {
119
        $this->_sValue = $sValue;
120
        return $this;
121
    }
122
123
    /**
124
     * get the Label
125
     *
126
     * @access public
127
     * @return string
128
     */
129
    public function getLabel() : string
130
    {
131
        return $this->_sLabel;
132
    }
133
134
    /**
135
     * set the Label
136
     *
137
     * @access public
138
     * @param  string $sLabel Label of input;
139
     * @return \Venus\lib\Form\Input
140
     */
141
    public function setLabel(string $sLabel) : Input
142
    {
143
        $this->_sLabel = $sLabel;
144
        return $this;
145
    }
146
147
    /**
148
     * if the button is clicked
149
     *
150
     * @access public
151
     * @param  string $sType type of input;
152
     * @return boolean
153
     */
154
    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...
155
    {
156
        if ($this->getType() === 'submit' || $this->getType() === 'button') {
157
158
            if (isset($_POST[$this->getName()])) { return true; }
159
        }
160
161
        return false;
162
    }
163
164
    /**
165
     * get the <html>
166
     *
167
     * @access public
168
     * @return string
169
     */
170
    public function fetch() : string
171
    {
172
        $sContent = '';
173
174
        if ($this->getType() === 'text' || $this->getType() === 'password' || $this->getType() === 'file'
175
            || $this->getType() === 'tel' || $this->getType() === 'url' || $this->getType() === 'email'
176
            || $this->getType() === 'search' || $this->getType() === 'date' || $this->getType() === 'time'
177
            || $this->getType() === 'datetime' || $this->getType() === 'month' || $this->getType() === 'week'
178
            || $this->getType() === 'number' || $this->getType() === 'range' || $this->getType() === 'color') {
179
180
            $sContent .= '<label>'.$this->getLabel().'</label> ';
181
        }
182
183
        $sContent .= '<input type="'.$this->getType().'" name="'.$this->getName().'"';
184
185
        if ($this->getValue() !== null) { $sContent .= ' value="'.$this->getValue().'"'; }
186
187
        $sContent .= '/>';
188
189
        return $sContent;
190
    }
191
}
192