| Total Complexity | 101 |
| Total Lines | 376 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 28 | class Form implements interfaceForm |
||
| 29 | { |
||
| 30 | |||
| 31 | /** |
||
| 32 | * open form |
||
| 33 | * |
||
| 34 | * This method return the form element <form... |
||
| 35 | * |
||
| 36 | * @param array(id, name, class, onsubmit, method, action, files, style) |
||
|
|
|||
| 37 | * |
||
| 38 | * @return string |
||
| 39 | */ |
||
| 40 | public static function open($params = array()) |
||
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * closed the form |
||
| 63 | * |
||
| 64 | * @return string |
||
| 65 | */ |
||
| 66 | public static function close() |
||
| 69 | } |
||
| 70 | |||
| 71 | /** |
||
| 72 | * textBox |
||
| 73 | * |
||
| 74 | * This method creates a textarea element |
||
| 75 | * |
||
| 76 | * @param array(id, name, class, onclick, columns, rows, disabled, placeholder, style, value) |
||
| 77 | * |
||
| 78 | * @return string |
||
| 79 | */ |
||
| 80 | public static function textBox($params = array()) |
||
| 81 | { |
||
| 82 | |||
| 83 | if (!is_array($params)) { |
||
| 84 | throw new \InvalidArgumentException("Arguments is not a Array" . print_r($params, true)); |
||
| 85 | } |
||
| 86 | $o = '<textarea'; |
||
| 87 | |||
| 88 | $o .= (isset($params['cols'])) ? " cols='{$params['cols']}'" : ''; |
||
| 89 | $o .= (isset($params['rows'])) ? " rows='{$params['rows']}'" : ''; |
||
| 90 | $o .= (isset($params['disabled'])) ? " disabled='{$params['disabled']}'" : ''; |
||
| 91 | $o .= (isset($params['maxlength'])) ? " maxlength='{$params['maxlength']}'" : ''; |
||
| 92 | $o .= (isset($params['style'])) ? " style='{$params['style']}'" : ''; |
||
| 93 | $o .= (isset($params['required'])) ? " required='required'" : ''; |
||
| 94 | $o .= '>'; |
||
| 95 | $o .= (isset($params['value'])) ? $params['value'] : ''; |
||
| 96 | $o .= "</textarea>\n"; |
||
| 97 | return $o; |
||
| 98 | } |
||
| 99 | |||
| 100 | /** |
||
| 101 | * input |
||
| 102 | * |
||
| 103 | * This method returns a input text element. |
||
| 104 | * |
||
| 105 | * @param array(id, name, class, onclick, value, length, width, disable,placeholder) |
||
| 106 | * |
||
| 107 | * @return string |
||
| 108 | */ |
||
| 109 | public static function input($params = array()) |
||
| 110 | { |
||
| 111 | |||
| 112 | if (!is_array($params)) { |
||
| 113 | throw new \InvalidArgumentException("Arguments is not a Array" . print_r($params, true)); |
||
| 114 | } |
||
| 115 | |||
| 116 | $o = '<input '; |
||
| 117 | $o .= self::param_mix($params); |
||
| 118 | $o .= (isset($params['onkeypress'])) ? " onkeypress='{$params['onkeypress']}'" : ''; |
||
| 119 | $o .= (isset($params['length'])) ? " maxlength='{$params['length']}'" : ''; |
||
| 120 | $o .= (isset($params['width'])) ? " style='width:{$params['width']}px;'" : ''; |
||
| 121 | $o .= (isset($params['disabled'])) ? " disabled='{$params['disabled']}'" : ''; |
||
| 122 | $o .= (isset($params['accept'])) ? " accept='{$params['accept']}'" : ''; |
||
| 123 | $o .= (isset($params['maxlength'])) ? " maxlength='{$params['maxlength']}'" : ''; |
||
| 124 | $o .= (isset($params['minlength'])) ? " minlength='{$params['minlength']}'" : ''; |
||
| 125 | $o .= (isset($params['autocomplete'])) ? " autocomplete='{$params['autocomplete']}'" : ''; |
||
| 126 | $o .= (isset($params['autofocus'])) ? " autofocus" : ''; |
||
| 127 | $o .= " />\n"; |
||
| 128 | return $o; |
||
| 129 | } |
||
| 130 | |||
| 131 | /** |
||
| 132 | * select |
||
| 133 | * |
||
| 134 | * This method returns a select html element. |
||
| 135 | * It can be given a param called value which then will be preselected |
||
| 136 | * data has to be array(k=>v) |
||
| 137 | * |
||
| 138 | * @param array(id, name, class, onclick, disabled) |
||
| 139 | * |
||
| 140 | * @return string |
||
| 141 | */ |
||
| 142 | public static function select($params = array()) |
||
| 169 | } |
||
| 170 | |||
| 171 | /** |
||
| 172 | * checkboxMulti |
||
| 173 | * |
||
| 174 | * This method returns multiple checkbox elements in order given in an array |
||
| 175 | * For checking of checkbox pass checked |
||
| 176 | * Each checkbox should look like array(0=>array('id'=>'1', 'name'=>'cb[]', 'value'=>'x', 'label'=>'label_text' )) |
||
| 177 | * |
||
| 178 | * @param array(array(id, name, value, class, checked, disabled)) |
||
| 179 | * |
||
| 180 | * @return string |
||
| 181 | */ |
||
| 182 | public static function checkbox($params = array()) |
||
| 183 | { |
||
| 184 | |||
| 185 | if (!is_array($params)) { |
||
| 186 | throw new \InvalidArgumentException("Arguments is not a Array" . print_r($params, true)); |
||
| 187 | } |
||
| 188 | $o = ''; |
||
| 189 | $x = 0; |
||
| 190 | foreach ($params as $k => $v) { |
||
| 191 | $v['id'] = (isset($v['id'])) ? $v['id'] : "cb_id_{$x}_" . rand(1000, 9999); |
||
| 192 | $o .= "<input type='checkbox'"; |
||
| 193 | $o .= self::param_mix($params); |
||
| 194 | $o .= (isset($v['checked'])) ? " checked='checked'" : ''; |
||
| 195 | $o .= (isset($v['disabled'])) ? " disabled='{$v['disabled']}'" : ''; |
||
| 196 | $o .= " />\n"; |
||
| 197 | $o .= (isset($v['label'])) ? "<label for='{$v['id']}'>{$v['label']}</label> " : ''; |
||
| 198 | $x++; |
||
| 199 | } |
||
| 200 | |||
| 201 | return $o; |
||
| 202 | } |
||
| 203 | |||
| 204 | /** |
||
| 205 | * radioMulti |
||
| 206 | * |
||
| 207 | * This method returns radio elements in order given in an array |
||
| 208 | * For selection pass checked |
||
| 209 | * Each radio should look like array(0=>array('id'=>'1', 'name'=>'rd[]', 'value'=>'x', 'label'=>'label_text' )) |
||
| 210 | * |
||
| 211 | * @param array(array(id, name, value, class, checked, disabled, label)) |
||
| 212 | * |
||
| 213 | * @return string |
||
| 214 | */ |
||
| 215 | public static function radio($params = array()) |
||
| 216 | { |
||
| 217 | |||
| 218 | if (!is_array($params)) { |
||
| 219 | throw new \InvalidArgumentException("Arguments is not a Array" . print_r($params, true)); |
||
| 220 | } |
||
| 221 | |||
| 222 | $o = ''; |
||
| 223 | $x = 0; |
||
| 224 | foreach ($params as $k => $v) { |
||
| 225 | $v['id'] = (isset($v['id'])) ? $v['id'] : "rd_id_{$x}_" . rand(1000, 9999); |
||
| 226 | $o .= "<input type='radio'"; |
||
| 227 | $o .= self::param_mix($params); |
||
| 228 | $o .= (isset($v['checked'])) ? " checked='checked'" : ''; |
||
| 229 | $o .= (isset($v['disabled'])) ? " disabled='{$v['disabled']}'" : ''; |
||
| 230 | $o .= " />\n"; |
||
| 231 | $o .= (isset($v['label'])) ? "<label for='{$v['id']}'>{$v['label']}</label> " : ''; |
||
| 232 | $x++; |
||
| 233 | } |
||
| 234 | |||
| 235 | return $o; |
||
| 236 | } |
||
| 237 | |||
| 238 | /** |
||
| 239 | * This method returns a button element given the params for settings |
||
| 240 | * |
||
| 241 | * @param array(id, name, class, onclick, value, disabled) |
||
| 242 | * |
||
| 243 | * @return string |
||
| 244 | */ |
||
| 245 | public static function button($params = array()) |
||
| 246 | { |
||
| 247 | |||
| 248 | if (!is_array($params)) { |
||
| 249 | throw new \InvalidArgumentException("Arguments is not a Array" . print_r($params, true)); |
||
| 250 | } |
||
| 251 | |||
| 252 | $o = "<button type='submit'"; |
||
| 253 | $o .= self::param_mix($params); |
||
| 254 | $o .= (isset($params['onclick'])) ? " onclick='{$params['onclick']}'" : ''; |
||
| 255 | $o .= (isset($params['disabled'])) ? " disabled='{$params['disabled']}'" : ''; |
||
| 256 | $o .= ">"; |
||
| 257 | $o .= (isset($params['iclass'])) ? "<i class='fa {$params['iclass']}'></i> " : ''; |
||
| 258 | $o .= "</button>\n"; |
||
| 259 | return $o; |
||
| 260 | } |
||
| 261 | |||
| 262 | /** |
||
| 263 | * This method returns a submit button element given the params for settings |
||
| 264 | * |
||
| 265 | * @param array(id, name, class, onclick, value, disabled) |
||
| 266 | * |
||
| 267 | * @return string |
||
| 268 | */ |
||
| 269 | public static function submit($params = array()) |
||
| 270 | { |
||
| 271 | |||
| 272 | if (!is_array($params)) { |
||
| 273 | throw new \InvalidArgumentException("Arguments is not a Array" . print_r($params, true)); |
||
| 274 | } |
||
| 275 | |||
| 276 | $o = '<input type="submit"'; |
||
| 277 | $o .= self::param_mix($params); |
||
| 278 | $o .= (isset($params['onclick'])) ? " onclick='{$params['onclick']}'" : ''; |
||
| 279 | $o .= (isset($params['disabled'])) ? " disabled='{$params['disabled']}'" : ''; |
||
| 280 | $o .= " />\n"; |
||
| 281 | return $o; |
||
| 282 | } |
||
| 283 | |||
| 284 | /** |
||
| 285 | * This method returns a hidden input elements given its params |
||
| 286 | * |
||
| 287 | * @param array(id, name, class, value) |
||
| 288 | * |
||
| 289 | * @return string |
||
| 290 | */ |
||
| 291 | public static function hidden($params = array()) |
||
| 305 | } |
||
| 306 | |||
| 307 | /** |
||
| 308 | * This method returns a table element given the params for settings |
||
| 309 | * |
||
| 310 | * @param [ 'thead' => [ 'a', 'b' ], 'tbody' => [ 'ax', 'bx'], 'class' => 'xxxxxx', ] ; |
||
| 311 | * |
||
| 312 | * @return string |
||
| 313 | */ |
||
| 314 | public static function table($params = array()) |
||
| 315 | { |
||
| 316 | |||
| 317 | if (!is_array($params)) { |
||
| 318 | throw new \InvalidArgumentException("Arguments is not a Array" . print_r($params, true)); |
||
| 319 | } |
||
| 320 | |||
| 321 | $o = "<table "; |
||
| 322 | $o .= (isset($params['class'])) ? " class='{$params['class']}'" : ''; |
||
| 323 | $o .= ">"; |
||
| 324 | |||
| 325 | $o .= "<thead>"; |
||
| 326 | $o .= "<tr>"; |
||
| 327 | if (isset($params['thead']) && is_array($params['thead'])) { |
||
| 328 | foreach ($params['thead'] as $key => $value) { |
||
| 329 | |||
| 330 | if (isset($params['th']) && $params['th'] == $key) { |
||
| 331 | $o .= "<th>" . $value . "</th>"; |
||
| 332 | } else { |
||
| 333 | $o .= "<th>" . $value . "</th>"; |
||
| 334 | } |
||
| 335 | } |
||
| 336 | } |
||
| 337 | $o .= " </tr>"; |
||
| 338 | $o .= "</thead>"; |
||
| 339 | |||
| 340 | $o .= "<tfoot>"; |
||
| 341 | $o .= "<tr>"; |
||
| 342 | if (isset($params['tfoot']) && is_array($params['tfoot'])) { |
||
| 343 | foreach ($params['tfoot'] as $key => $value) { |
||
| 344 | if (isset($params['td']) && $params['td'] == $key) { |
||
| 345 | $o .= "<td>" . $value . "</td>"; |
||
| 346 | } else { |
||
| 347 | $o .= "<td>" . $value . "</td>"; |
||
| 348 | } |
||
| 349 | } |
||
| 350 | } |
||
| 351 | $o .= " </tr>"; |
||
| 352 | $o .= "</tfoot>"; |
||
| 353 | |||
| 354 | $o .= "<tbody>"; |
||
| 355 | $o .= "<tr>"; |
||
| 356 | if (isset($params['tbody']) && is_array($params['tbody'])) { |
||
| 357 | foreach ($params['tbody'] as $key => $value) { |
||
| 358 | if (isset($params['td']) && $params['td'] == $key) { |
||
| 359 | $o .= "<td>" . $value . "</td>"; |
||
| 360 | } else { |
||
| 361 | $o .= "<td>" . $value . "</td>"; |
||
| 362 | } |
||
| 363 | } |
||
| 364 | } |
||
| 365 | $o .= " </tr>"; |
||
| 366 | $o .= "</tbody>"; |
||
| 367 | $o .= "</table>"; |
||
| 368 | return $o; |
||
| 369 | } |
||
| 370 | |||
| 371 | /** |
||
| 372 | * |
||
| 373 | * @since 1.0.6 |
||
| 374 | * |
||
| 375 | * @param [ 'for' => 'exemplo-title' ], ['title' => 'Example Title' ]; |
||
| 376 | * |
||
| 377 | * @return string |
||
| 378 | */ |
||
| 379 | |||
| 380 | private static function param_mix($params = array()) { |
||
| 392 | |||
| 393 | } |
||
| 394 | public static function label($params = array()) |
||
| 395 | { |
||
| 396 | $o = "<label"; |
||
| 404 | } |
||
| 405 | |||
| 406 | } |
||
| 407 |
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