Total Complexity | 68 |
Total Lines | 282 |
Duplicated Lines | 0 % |
Changes | 2 | ||
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 .= self::param_mix($params); |
||
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['autocomplete'])) ? " autocomplete='{$params['autocomplete']}'" : ''; |
||
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 .= (isset($params['required'])) ? " required='required'" : ''; |
||
85 | $o .= '>'; |
||
86 | $o .= (isset($params['value'])) ? $params['value'] : ''; |
||
87 | $o .= "</textarea>\n"; |
||
88 | return $o; |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * input |
||
93 | * |
||
94 | * This method returns a input text element. |
||
95 | * |
||
96 | * @param array(id, name, class, onclick, value, length, width, disable,placeholder) |
||
97 | * |
||
98 | * @return string |
||
99 | */ |
||
100 | public static function input($params = array()) |
||
119 | } |
||
120 | |||
121 | /** |
||
122 | * select |
||
123 | * |
||
124 | * This method returns a select html element. |
||
125 | * It can be given a param called value which then will be preselected |
||
126 | * data has to be array(k=>v) |
||
127 | * |
||
128 | * @param array(id, name, class, onclick, disabled) |
||
129 | * |
||
130 | * @return string |
||
131 | */ |
||
132 | public static function select($params = array()) |
||
133 | { |
||
134 | if (!is_array($params)) { |
||
135 | throw new \InvalidArgumentException("Arguments is not a Array" . print_r($params, true)); |
||
136 | } |
||
137 | |||
138 | $o = "<select"; |
||
139 | $o .= self::param_mix($params); |
||
140 | $o .= (isset($params['width'])) ? " style='width:{$params['width']}px;'" : ''; |
||
141 | $o .= ">\n"; |
||
142 | $o .= "<option value=''>Select</option>\n"; |
||
143 | if (isset($params['data']) && is_array($params['data'])) { |
||
144 | foreach ($params['data'] as $k => $v) { |
||
145 | if (isset($params['value']) && $params['value'] == $k) { |
||
146 | $o .= "<option value='{$k}' selected='selected'>{$v}</option>\n"; |
||
147 | } else { |
||
148 | $o .= "<option value='{$k}'>{$v}</option>\n"; |
||
149 | } |
||
150 | } |
||
151 | |||
152 | throw new \InvalidArgumentException("Arguments is not valid " . print_r($params, true)); |
||
153 | |||
154 | |||
155 | } |
||
156 | $o .= "</select>\n"; |
||
157 | return $o; |
||
158 | } |
||
159 | |||
160 | /** |
||
161 | * checkboxMulti |
||
162 | * |
||
163 | * This method returns multiple checkbox elements in order given in an array |
||
164 | * For checking of checkbox pass checked |
||
165 | * Each checkbox should look like array(0=>array('id'=>'1', 'name'=>'cb[]', 'value'=>'x', 'label'=>'label_text' )) |
||
166 | * |
||
167 | * @param array(array(id, name, value, class, checked, disabled)) |
||
168 | * |
||
169 | * @return string |
||
170 | */ |
||
171 | public static function checkbox($params = array()) |
||
172 | { |
||
173 | |||
174 | if (!is_array($params)) { |
||
175 | throw new \InvalidArgumentException("Arguments is not a Array" . print_r($params, true)); |
||
176 | } |
||
177 | $o = ''; |
||
178 | $x = 0; |
||
179 | foreach ($params as $k => $v) { |
||
180 | $v['id'] = (isset($v['id'])) ? $v['id'] : "cb_id_{$x}_" . rand(1000, 9999); |
||
181 | $o .= "<input type='checkbox'"; |
||
182 | $o .= self::param_mix($params); |
||
183 | $o .= (isset($v['checked'])) ? " checked='checked'" : ''; |
||
184 | $o .= (isset($v['disabled'])) ? " disabled='{$v['disabled']}'" : ''; |
||
185 | $o .= " />\n"; |
||
186 | $o .= (isset($v['label'])) ? "<label for='{$v['id']}'>{$v['label']}</label> " : ''; |
||
187 | $x++; |
||
188 | } |
||
189 | |||
190 | return $o; |
||
191 | } |
||
192 | |||
193 | /** |
||
194 | * radioMulti |
||
195 | * |
||
196 | * This method returns radio elements in order given in an array |
||
197 | * For selection pass checked |
||
198 | * Each radio should look like array(0=>array('id'=>'1', 'name'=>'rd[]', 'value'=>'x', 'label'=>'label_text' )) |
||
199 | * |
||
200 | * @param array(array(id, name, value, class, checked, disabled, label)) |
||
201 | * |
||
202 | * @return string |
||
203 | */ |
||
204 | public static function radio($params = array()) |
||
205 | { |
||
206 | |||
207 | if (!is_array($params)) { |
||
208 | throw new \InvalidArgumentException("Arguments is not a Array" . print_r($params, true)); |
||
209 | } |
||
210 | |||
211 | $o = ''; |
||
212 | $x = 0; |
||
213 | foreach ($params as $k => $v) { |
||
214 | $v['id'] = (isset($v['id'])) ? $v['id'] : "rd_id_{$x}_" . rand(1000, 9999); |
||
215 | $o .= "<input type='radio'"; |
||
216 | $o .= self::param_mix($params); |
||
217 | $o .= (isset($v['checked'])) ? " checked='checked'" : ''; |
||
218 | $o .= (isset($v['disabled'])) ? " disabled='{$v['disabled']}'" : ''; |
||
219 | $o .= " />\n"; |
||
220 | $o .= (isset($v['label'])) ? "<label for='{$v['id']}'>{$v['label']}</label> " : ''; |
||
221 | $x++; |
||
222 | } |
||
223 | |||
224 | return $o; |
||
225 | } |
||
226 | |||
227 | /** |
||
228 | * This method returns a button element given the params for settings |
||
229 | * |
||
230 | * @param array(id, name, class, onclick, value, disabled) |
||
231 | * |
||
232 | * @return string |
||
233 | */ |
||
234 | public static function button($params = array()) |
||
235 | { |
||
236 | |||
237 | if (!is_array($params)) { |
||
238 | throw new \InvalidArgumentException("Arguments is not a Array" . print_r($params, true)); |
||
239 | } |
||
240 | |||
241 | $o = "<button type='submit'"; |
||
242 | $o .= self::param_mix($params); |
||
243 | $o .= (isset($params['onclick'])) ? " onclick='{$params['onclick']}'" : ''; |
||
244 | $o .= ">"; |
||
245 | $o .= (isset($params['class'])) ? "<i class='fa {$params['iclass']}'></i> " : ''; |
||
246 | $o .= "</button>\n"; |
||
247 | return $o; |
||
248 | } |
||
249 | |||
250 | /** |
||
251 | * This method returns a submit button element given the params for settings |
||
252 | * |
||
253 | * @param array(id, name, class, onclick, value, disabled) |
||
254 | * |
||
255 | * @return string |
||
256 | */ |
||
257 | public static function submit($params = array()) |
||
258 | { |
||
259 | |||
260 | if (!is_array($params)) { |
||
261 | throw new \InvalidArgumentException("Arguments is not a Array" . print_r($params, true)); |
||
262 | } |
||
263 | |||
264 | $o = '<input type="submit"'; |
||
265 | $o .= self::param_mix($params); |
||
266 | $o .= (isset($params['onclick'])) ? " onclick='{$params['onclick']}'" : ''; |
||
267 | $o .= " />\n"; |
||
268 | return $o; |
||
269 | } |
||
270 | |||
271 | /** |
||
272 | * |
||
273 | * @since 1.0.6 |
||
274 | * |
||
275 | * @param array('for' => 'exemplo-title' , 'title' => 'Example Title'); |
||
276 | * |
||
277 | * @return string |
||
278 | */ |
||
279 | |||
280 | private static function param_mix($params = array()) { |
||
281 | |||
282 | if (!is_array($params)) { |
||
283 | throw new \InvalidArgumentException("Arguments is not a Array" . print_r($params, true)); |
||
284 | } |
||
285 | $o =''; |
||
286 | $o .= (isset($params['id'])) ? " id='{$params['id']}'" : ''; |
||
287 | $o .= (isset($params['name'])) ? " name='{$params['name']}'" : ''; |
||
288 | $o .= (isset($params['class'])) ? " class='form-input textbox {$params['class']}'" : ''; |
||
289 | $o .= (isset($params['onclick'])) ? " onclick='{$params['onclick']}'" : ''; |
||
290 | $o .= (isset($params['disabled'])) ? " disabled='{$params['disabled']}'" : ''; |
||
291 | $o .= (isset($params['required'])) ? " required='required'" : ''; |
||
292 | $o .= (isset($params['type'])) ? " type='{$params['type']}'" : 'type="text"'; |
||
293 | return $o; |
||
294 | |||
295 | } |
||
296 | public static function label($params = array()) |
||
306 | } |
||
307 | |||
308 | } |
||
309 |
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