| Total Complexity | 72 |
| Total Lines | 285 |
| 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()) |
||
| 41 | { |
||
| 42 | |||
| 43 | if (!is_array($params)) { |
||
| 44 | throw new \InvalidArgumentException("Arguments is not a Array" . print_r($params, true)); |
||
| 45 | } |
||
| 46 | $o = '<form'; |
||
| 47 | $o .= self::param_mix($params); |
||
| 48 | $o .= (isset($params['onsubmit'])) ? " onsubmit='{$params['onsubmit']}'" : ''; |
||
| 49 | $o .= (isset($params['method'])) ? " method='{$params['method']}'" : ' method="get"'; |
||
| 50 | $o .= (isset($params['action'])) ? " action='{$params['action']}'" : ''; |
||
| 51 | $o .= (isset($params['files'])) ? " enctype='multipart/form-data'" : ''; |
||
| 52 | $o .= (isset($params['role'])) ? " role='{$params['role']}'" : ''; |
||
| 53 | $o .= (isset($params['autocomplete'])) ? " autocomplete='{$params['autocomplete']}'" : ''; |
||
| 54 | $o .= '>'; |
||
| 55 | return $o . "\n"; |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * closed the form |
||
| 60 | * |
||
| 61 | * @return string |
||
| 62 | */ |
||
| 63 | public static function close() |
||
| 64 | { |
||
| 65 | return "</form>\n"; |
||
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * textBox |
||
| 70 | * |
||
| 71 | * This method creates a textarea element |
||
| 72 | * |
||
| 73 | * @param array(id, name, class, onclick, columns, rows, disabled, placeholder, style, value) |
||
| 74 | * |
||
| 75 | * @return string |
||
| 76 | */ |
||
| 77 | public static function textBox($params = array()) |
||
| 78 | { |
||
| 79 | |||
| 80 | if (!is_array($params)) { |
||
| 81 | throw new \InvalidArgumentException("Arguments is not a Array" . print_r($params, true)); |
||
| 82 | } |
||
| 83 | $o = '<textarea'; |
||
| 84 | $o .= self::param_mix($params); |
||
| 85 | $o .= (isset($params['cols'])) ? " cols='{$params['cols']}'" : ''; |
||
| 86 | $o .= (isset($params['rows'])) ? " rows='{$params['rows']}'" : ''; |
||
| 87 | $o .= (isset($params['disabled'])) ? " disabled='{$params['disabled']}'" : ''; |
||
| 88 | $o .= (isset($params['maxlength'])) ? " maxlength='{$params['maxlength']}'" : ''; |
||
| 89 | $o .= (isset($params['required'])) ? " required='required'" : ''; |
||
| 90 | $o .= '>'; |
||
| 91 | $o .= (isset($params['value'])) ? $params['value'] : ''; |
||
| 92 | $o .= "</textarea>\n"; |
||
| 93 | return $o; |
||
| 94 | } |
||
| 95 | |||
| 96 | /** |
||
| 97 | * input |
||
| 98 | * |
||
| 99 | * This method returns a input text element. |
||
| 100 | * |
||
| 101 | * @param array(id, name, class, onclick, value, length, width, disable,placeholder) |
||
| 102 | * |
||
| 103 | * @return string |
||
| 104 | */ |
||
| 105 | public static function input($params = array()) |
||
| 106 | { |
||
| 107 | |||
| 108 | if (!is_array($params)) { |
||
| 109 | throw new \InvalidArgumentException("Arguments is not a Array" . print_r($params, true)); |
||
| 110 | } |
||
| 111 | |||
| 112 | $o = '<input '; |
||
| 113 | $o .= self::param_mix($params); |
||
| 114 | $o .= (isset($params['onkeypress'])) ? " onkeypress='{$params['onkeypress']}'" : ''; |
||
| 115 | $o .= (isset($params['length'])) ? " maxlength='{$params['length']}'" : ''; |
||
| 116 | $o .= (isset($params['width'])) ? " style='width:{$params['width']}px;'" : ''; |
||
| 117 | $o .= (isset($params['disabled'])) ? " disabled='{$params['disabled']}'" : ''; |
||
| 118 | $o .= (isset($params['accept'])) ? " accept='{$params['accept']}'" : ''; |
||
| 119 | $o .= (isset($params['maxlength'])) ? " maxlength='{$params['maxlength']}'" : ''; |
||
| 120 | $o .= (isset($params['minlength'])) ? " minlength='{$params['minlength']}'" : ''; |
||
| 121 | $o .= (isset($params['autocomplete'])) ? " autocomplete='{$params['autocomplete']}'" : ''; |
||
| 122 | $o .= (isset($params['autofocus'])) ? " autofocus" : ''; |
||
| 123 | $o .= " />\n"; |
||
| 124 | return $o; |
||
| 125 | } |
||
| 126 | |||
| 127 | /** |
||
| 128 | * select |
||
| 129 | * |
||
| 130 | * This method returns a select html element. |
||
| 131 | * It can be given a param called value which then will be preselected |
||
| 132 | * data has to be array(k=>v) |
||
| 133 | * |
||
| 134 | * @param array(id, name, class, onclick, disabled) |
||
| 135 | * |
||
| 136 | * @return string |
||
| 137 | */ |
||
| 138 | public static function select($params = array()) |
||
| 164 | } |
||
| 165 | |||
| 166 | /** |
||
| 167 | * checkboxMulti |
||
| 168 | * |
||
| 169 | * This method returns multiple checkbox elements in order given in an array |
||
| 170 | * For checking of checkbox pass checked |
||
| 171 | * Each checkbox should look like array(0=>array('id'=>'1', 'name'=>'cb[]', 'value'=>'x', 'label'=>'label_text' )) |
||
| 172 | * |
||
| 173 | * @param array(array(id, name, value, class, checked, disabled)) |
||
| 174 | * |
||
| 175 | * @return string |
||
| 176 | */ |
||
| 177 | public static function checkbox($params = array()) |
||
| 178 | { |
||
| 179 | |||
| 180 | if (!is_array($params)) { |
||
| 181 | throw new \InvalidArgumentException("Arguments is not a Array" . print_r($params, true)); |
||
| 182 | } |
||
| 183 | $o = ''; |
||
| 184 | $x = 0; |
||
| 185 | foreach ($params as $k => $v) { |
||
| 186 | $v['id'] = (isset($v['id'])) ? $v['id'] : "cb_id_{$x}_" . rand(1000, 9999); |
||
| 187 | $o .= "<input type='checkbox'"; |
||
| 188 | $o .= self::param_mix($params); |
||
| 189 | $o .= (isset($v['checked'])) ? " checked='checked'" : ''; |
||
| 190 | $o .= (isset($v['disabled'])) ? " disabled='{$v['disabled']}'" : ''; |
||
| 191 | $o .= " />\n"; |
||
| 192 | $o .= (isset($v['label'])) ? "<label for='{$v['id']}'>{$v['label']}</label> " : ''; |
||
| 193 | $x++; |
||
| 194 | } |
||
| 195 | |||
| 196 | return $o; |
||
| 197 | } |
||
| 198 | |||
| 199 | /** |
||
| 200 | * radioMulti |
||
| 201 | * |
||
| 202 | * This method returns radio elements in order given in an array |
||
| 203 | * For selection pass checked |
||
| 204 | * Each radio should look like array(0=>array('id'=>'1', 'name'=>'rd[]', 'value'=>'x', 'label'=>'label_text' )) |
||
| 205 | * |
||
| 206 | * @param array(array(id, name, value, class, checked, disabled, label)) |
||
| 207 | * |
||
| 208 | * @return string |
||
| 209 | */ |
||
| 210 | public static function radio($params = array()) |
||
| 211 | { |
||
| 212 | |||
| 213 | if (!is_array($params)) { |
||
| 214 | throw new \InvalidArgumentException("Arguments is not a Array" . print_r($params, true)); |
||
| 215 | } |
||
| 216 | |||
| 217 | $o = ''; |
||
| 218 | $x = 0; |
||
| 219 | foreach ($params as $k => $v) { |
||
| 220 | $v['id'] = (isset($v['id'])) ? $v['id'] : "rd_id_{$x}_" . rand(1000, 9999); |
||
| 221 | $o .= "<input type='radio'"; |
||
| 222 | $o .= self::param_mix($params); |
||
| 223 | $o .= (isset($v['checked'])) ? " checked='checked'" : ''; |
||
| 224 | $o .= (isset($v['disabled'])) ? " disabled='{$v['disabled']}'" : ''; |
||
| 225 | $o .= " />\n"; |
||
| 226 | $o .= (isset($v['label'])) ? "<label for='{$v['id']}'>{$v['label']}</label> " : ''; |
||
| 227 | $x++; |
||
| 228 | } |
||
| 229 | |||
| 230 | return $o; |
||
| 231 | } |
||
| 232 | |||
| 233 | /** |
||
| 234 | * This method returns a button element given the params for settings |
||
| 235 | * |
||
| 236 | * @param array(id, name, class, onclick, value, disabled) |
||
| 237 | * |
||
| 238 | * @return string |
||
| 239 | */ |
||
| 240 | public static function button($params = array()) |
||
| 241 | { |
||
| 242 | |||
| 243 | if (!is_array($params)) { |
||
| 244 | throw new \InvalidArgumentException("Arguments is not a Array" . print_r($params, true)); |
||
| 245 | } |
||
| 246 | |||
| 247 | $o = "<button type='submit'"; |
||
| 248 | $o .= self::param_mix($params); |
||
| 249 | $o .= (isset($params['onclick'])) ? " onclick='{$params['onclick']}'" : ''; |
||
| 250 | $o .= (isset($params['disabled'])) ? " disabled='{$params['disabled']}'" : ''; |
||
| 251 | $o .= ">"; |
||
| 252 | $o .= (isset($params['class'])) ? "<i class='fa {$params['iclass']}'></i> " : ''; |
||
| 253 | $o .= "</button>\n"; |
||
| 254 | return $o; |
||
| 255 | } |
||
| 256 | |||
| 257 | /** |
||
| 258 | * This method returns a submit button element given the params for settings |
||
| 259 | * |
||
| 260 | * @param array(id, name, class, onclick, value, disabled) |
||
| 261 | * |
||
| 262 | * @return string |
||
| 263 | */ |
||
| 264 | public static function submit($params = array()) |
||
| 265 | { |
||
| 266 | |||
| 267 | if (!is_array($params)) { |
||
| 268 | throw new \InvalidArgumentException("Arguments is not a Array" . print_r($params, true)); |
||
| 269 | } |
||
| 270 | |||
| 271 | $o = '<input type="submit"'; |
||
| 272 | $o .= self::param_mix($params); |
||
| 273 | $o .= (isset($params['onclick'])) ? " onclick='{$params['onclick']}'" : ''; |
||
| 274 | $o .= (isset($params['disabled'])) ? " disabled='{$params['disabled']}'" : ''; |
||
| 275 | $o .= " />\n"; |
||
| 276 | return $o; |
||
| 277 | } |
||
| 278 | |||
| 279 | /** |
||
| 280 | * |
||
| 281 | * @since 1.0.6 |
||
| 282 | * |
||
| 283 | * @param [ 'for' => 'exemplo-title' ], ['title' => 'Example Title' ]; |
||
| 284 | * |
||
| 285 | * @return string |
||
| 286 | */ |
||
| 287 | |||
| 288 | private static function param_mix($params = array()) { |
||
| 301 | |||
| 302 | } |
||
| 303 | public static function label($params = array()) |
||
| 304 | { |
||
| 305 | $o = "<label"; |
||
| 313 | } |
||
| 314 | |||
| 315 | } |
||
| 316 |
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