Total Complexity | 68 |
Total Lines | 281 |
Duplicated Lines | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 0 |
Complex classes like Form often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Form, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
24 | class Form implements interfaceForm |
||
25 | { |
||
26 | |||
27 | /** |
||
28 | * open form |
||
29 | * |
||
30 | * This method return the form element <form... |
||
31 | * |
||
32 | * @param array(id, name, class, onsubmit, method, action, files, style) |
||
|
|||
33 | * |
||
34 | * @return string |
||
35 | */ |
||
36 | public static function open($params = array()) |
||
37 | { |
||
38 | |||
39 | if (!is_array($params)) { |
||
40 | throw new \InvalidArgumentException("Arguments is not a Array" . print_r($params, true)); |
||
41 | } |
||
42 | $o = '<form'; |
||
43 | $o .= (isset($params['id'])) ? " id='{$params['id']}'" : ''; |
||
44 | $o .= (isset($params['onsubmit'])) ? " onsubmit='{$params['onsubmit']}'" : ''; |
||
45 | $o .= (isset($params['method'])) ? " method='{$params['method']}'" : ' method="get"'; |
||
46 | $o .= (isset($params['action'])) ? " action='{$params['action']}'" : ''; |
||
47 | $o .= (isset($params['files'])) ? " enctype='multipart/form-data'" : ''; |
||
48 | $o .= (isset($params['role'])) ? " role='{$params['role']}'" : ''; |
||
49 | $o .= (isset($params['novalidate'])) ? " {$params['novalidate']}" : ''; |
||
50 | $o .= '>'; |
||
51 | return $o; |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * closed the form |
||
56 | * |
||
57 | * @return string |
||
58 | */ |
||
59 | public static function close() |
||
60 | { |
||
61 | return "</form>\n"; |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * textBox |
||
66 | * |
||
67 | * This method creates a textarea element |
||
68 | * |
||
69 | * @param array(id, name, class, onclick, columns, rows, disabled, placeholder, style, value) |
||
70 | * |
||
71 | * @return string |
||
72 | */ |
||
73 | public static function textBox($params = array()) |
||
74 | { |
||
75 | |||
76 | if (!is_array($params)) { |
||
77 | throw new \InvalidArgumentException("Arguments is not a Array" . print_r($params, true)); |
||
78 | } |
||
79 | $o = '<textarea'; |
||
80 | $o .= self::param_mix($params); |
||
81 | $o .= (isset($params['cols'])) ? " cols='{$params['cols']}'" : ''; |
||
82 | $o .= (isset($params['rows'])) ? " rows='{$params['rows']}'" : ''; |
||
83 | $o .= (isset($params['maxlength'])) ? " maxlength='{$params['maxlength']}'" : ''; |
||
84 | $o .= '>'; |
||
85 | $o .= (isset($params['value'])) ? $params['value'] : ''; |
||
86 | $o .= "</textarea>\n"; |
||
87 | return $o; |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * input |
||
92 | * |
||
93 | * This method returns a input text element. |
||
94 | * |
||
95 | * @param array(id, name, class, onclick, value, length, width, disable,placeholder) |
||
96 | * |
||
97 | * @return string |
||
98 | */ |
||
99 | public static function input($params = array()) |
||
100 | { |
||
101 | |||
102 | if (!is_array($params)) { |
||
103 | throw new \InvalidArgumentException("Arguments is not a Array" . print_r($params, true)); |
||
104 | } |
||
105 | |||
106 | $o = '<input '; |
||
107 | $o .= self::param_mix($params); |
||
108 | $o .= (isset($params['onkeypress'])) ? " onkeypress='{$params['onkeypress']}'" : ''; |
||
109 | $o .= (isset($params['length'])) ? " maxlength='{$params['length']}'" : ''; |
||
110 | $o .= (isset($params['accept'])) ? " accept='{$params['accept']}'" : ''; |
||
111 | $o .= (isset($params['maxlength'])) ? " maxlength='{$params['maxlength']}'" : ''; |
||
112 | $o .= (isset($params['minlength'])) ? " minlength='{$params['minlength']}'" : ''; |
||
113 | $o .= (isset($params['autocomplete'])) ? " autocomplete='{$params['autocomplete']}'" : ''; |
||
114 | $o .= (isset($params['autofocus'])) ? " autofocus" : ''; |
||
115 | $o .= " />\n"; |
||
116 | return $o; |
||
117 | } |
||
118 | |||
119 | /** |
||
120 | * select |
||
121 | * |
||
122 | * This method returns a select html element. |
||
123 | * It can be given a param called value which then will be preselected |
||
124 | * data has to be array(k=>v) |
||
125 | * |
||
126 | * @param array(id, name, class, onclick, disabled) |
||
127 | * |
||
128 | * @return string |
||
129 | */ |
||
130 | public static function select($params = array()) |
||
131 | { |
||
132 | if (!is_array($params)) { |
||
133 | throw new \InvalidArgumentException("Arguments is not a Array" . print_r($params, true)); |
||
134 | } |
||
135 | |||
136 | $o = "<select"; |
||
137 | $o .= self::param_mix($params); |
||
138 | $o .= (isset($params['width'])) ? " style='width:{$params['width']}px;'" : ''; |
||
139 | $o .= ">\n"; |
||
140 | $o .= "<option value=''>Select</option>\n"; |
||
141 | if (isset($params['data']) && is_array($params['data'])) { |
||
142 | foreach ($params['data'] as $k => $v) { |
||
143 | if (isset($params['value']) && $params['value'] == $k) { |
||
144 | $o .= "<option value='{$k}' selected='selected'>{$v}</option>\n"; |
||
145 | } else { |
||
146 | $o .= "<option value='{$k}'>{$v}</option>\n"; |
||
147 | } |
||
148 | } |
||
149 | |||
150 | throw new \InvalidArgumentException("Arguments is not valid " . print_r($params, true)); |
||
151 | |||
152 | |||
153 | } |
||
154 | $o .= "</select>\n"; |
||
155 | return $o; |
||
156 | } |
||
157 | |||
158 | /** |
||
159 | * checkboxMulti |
||
160 | * |
||
161 | * This method returns multiple checkbox elements in order given in an array |
||
162 | * For checking of checkbox pass checked |
||
163 | * Each checkbox should look like array(0=>array('id'=>'1', 'name'=>'cb[]', 'value'=>'x', 'label'=>'label_text' )) |
||
164 | * |
||
165 | * @param array(array(id, name, value, class, checked, disabled)) |
||
166 | * |
||
167 | * @return string |
||
168 | */ |
||
169 | public static function checkbox($params = array()) |
||
170 | { |
||
171 | |||
172 | if (!is_array($params)) { |
||
173 | throw new \InvalidArgumentException("Arguments is not a Array" . print_r($params, true)); |
||
174 | } |
||
175 | $o = ''; |
||
176 | $x = 0; |
||
177 | foreach ($params as $k => $v) { |
||
178 | $v['id'] = (isset($v['id'])) ? $v['id'] : "cb_id_{$x}_" . rand(1000, 9999); |
||
179 | $o .= "<input type='checkbox'"; |
||
180 | $o .= self::param_mix($params); |
||
181 | $o .= (isset($v['checked'])) ? " checked='checked'" : ''; |
||
182 | $o .= (isset($v['disabled'])) ? " disabled='{$v['disabled']}'" : ''; |
||
183 | $o .= " />\n"; |
||
184 | $o .= (isset($v['label'])) ? "<label for='{$v['id']}'>{$v['label']}</label> " : ''; |
||
185 | $x++; |
||
186 | } |
||
187 | |||
188 | return $o; |
||
189 | } |
||
190 | |||
191 | /** |
||
192 | * radioMulti |
||
193 | * |
||
194 | * This method returns radio elements in order given in an array |
||
195 | * For selection pass checked |
||
196 | * Each radio should look like array(0=>array('id'=>'1', 'name'=>'rd[]', 'value'=>'x', 'label'=>'label_text' )) |
||
197 | * |
||
198 | * @param array(array(id, name, value, class, checked, disabled, label)) |
||
199 | * |
||
200 | * @return string |
||
201 | */ |
||
202 | public static function radio($params = array()) |
||
203 | { |
||
204 | |||
205 | if (!is_array($params)) { |
||
206 | throw new \InvalidArgumentException("Arguments is not a Array" . print_r($params, true)); |
||
207 | } |
||
208 | |||
209 | $o = ''; |
||
210 | $x = 0; |
||
211 | foreach ($params as $k => $v) { |
||
212 | $v['id'] = (isset($v['id'])) ? $v['id'] : "rd_id_{$x}_" . rand(1000, 9999); |
||
213 | $o .= "<input type='radio'"; |
||
214 | $o .= self::param_mix($params); |
||
215 | $o .= (isset($v['checked'])) ? " checked='checked'" : ''; |
||
216 | $o .= (isset($v['disabled'])) ? " disabled='{$v['disabled']}'" : ''; |
||
217 | $o .= " />\n"; |
||
218 | $o .= (isset($v['label'])) ? "<label for='{$v['id']}'>{$v['label']}</label> " : ''; |
||
219 | $x++; |
||
220 | } |
||
221 | |||
222 | return $o; |
||
223 | } |
||
224 | |||
225 | /** |
||
226 | * This method returns a button element given the params for settings |
||
227 | * |
||
228 | * @param array(id, name, class, onclick, value, disabled) |
||
229 | * |
||
230 | * @return string |
||
231 | */ |
||
232 | public static function button($params = array()) |
||
233 | { |
||
234 | |||
235 | if (!is_array($params)) { |
||
236 | throw new \InvalidArgumentException("Arguments is not a Array" . print_r($params, true)); |
||
237 | } |
||
238 | |||
239 | $o = "<button type='submit'"; |
||
240 | $o .= self::param_mix($params); |
||
241 | $o .= (isset($params['onclick'])) ? " onclick='{$params['onclick']}'" : ''; |
||
242 | $o .= ">"; |
||
243 | $o .= (isset($params['class'])) ? "<i class='fa {$params['iclass']}'></i> " : ''; |
||
244 | $o .= "</button>\n"; |
||
245 | return $o; |
||
246 | } |
||
247 | |||
248 | /** |
||
249 | * This method returns a submit button element given the params for settings |
||
250 | * |
||
251 | * @param array(id, name, class, onclick, value, disabled) |
||
252 | * |
||
253 | * @return string |
||
254 | */ |
||
255 | public static function submit($params = array()) |
||
256 | { |
||
257 | |||
258 | if (!is_array($params)) { |
||
259 | throw new \InvalidArgumentException("Arguments is not a Array" . print_r($params, true)); |
||
260 | } |
||
261 | |||
262 | $o = '<input type="submit"'; |
||
263 | $o .= self::param_mix($params); |
||
264 | $o .= (isset($params['onclick'])) ? " onclick='{$params['onclick']}'" : ''; |
||
265 | $o .= " />\n"; |
||
266 | return $o; |
||
267 | } |
||
268 | |||
269 | /** |
||
270 | * |
||
271 | * @since 1.0.6 |
||
272 | * |
||
273 | * @param array |
||
274 | * |
||
275 | * @return string |
||
276 | */ |
||
277 | |||
278 | private static function param_mix($params = array()) { |
||
279 | |||
280 | if (!is_array($params)) { |
||
281 | throw new \InvalidArgumentException("Arguments is not a Array" . print_r($params, true)); |
||
282 | } |
||
283 | $o =''; |
||
284 | $o .= (isset($params['id'])) ? " id='{$params['id']}'" : ''; |
||
285 | $o .= (isset($params['name'])) ? " name='{$params['name']}'" : ''; |
||
286 | $o .= (isset($params['value'])) ? " value='{$params['value']}'" : ''; |
||
287 | $o .= (isset($params['class'])) ? " class='form-input textbox {$params['class']}'" : ''; |
||
288 | $o .= (isset($params['onclick'])) ? " onclick='{$params['onclick']}'" : ''; |
||
289 | $o .= (isset($params['disabled'])) ? " disabled='{$params['disabled']}'" : ''; |
||
290 | $o .= (isset($params['required'])) ? " required='required'" : ''; |
||
291 | $o .= (isset($params['type'])) ? " type='{$params['type']}'" : 'type="text"'; |
||
292 | return $o; |
||
293 | |||
294 | } |
||
295 | public static function label($params = array()) |
||
305 | } |
||
306 | |||
307 | } |
||
308 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths