| Conditions | 33 |
| Paths | 88 |
| Total Lines | 171 |
| Code Lines | 150 |
| Lines | 42 |
| Ratio | 24.56 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.
There are several approaches to avoid long parameter lists:
| 1 | <?php |
||
| 38 | public function createField($title = '', $name = '', $fieldtype = '', $ext = '', $options = '', $value = '', $custom = '0', $customtitle = null) |
||
| 39 | { |
||
| 40 | global $form, $myts, $moddir; |
||
| 41 | if ($customtitle == null) { |
||
| 42 | $customtitle = ''; |
||
| 43 | } |
||
| 44 | $multiple = false; |
||
| 45 | if ($ext != '') { |
||
| 46 | $ext_arr = explode('[|]', $ext); |
||
| 47 | foreach ($ext_arr as $ext_item) { |
||
| 48 | $ext_item_arr = explode('[=]', $ext_item); |
||
| 49 | $ext_item_name = $ext_item_arr[0]; |
||
| 50 | $ext_item_value = $ext_item_arr[1]; |
||
| 51 | |||
| 52 | switch ($ext_item_name) { |
||
| 53 | case 'cols': |
||
| 54 | $cols = $ext_item_value; |
||
| 55 | break; |
||
| 56 | case 'rows': |
||
| 57 | $rows = $ext_item_value; |
||
| 58 | break; |
||
| 59 | case 'size': |
||
| 60 | $size = $ext_item_value; |
||
| 61 | break; |
||
| 62 | case 'maxsize': |
||
| 63 | $maxsize = $ext_item_value; |
||
| 64 | break; |
||
| 65 | case 'multiple': |
||
| 66 | $multiple = true; |
||
| 67 | $size = 5; |
||
| 68 | case 'value': |
||
| 69 | if ($ext_item_value != '' and $value == '') { |
||
| 70 | $value = $ext_item_value; |
||
| 71 | } |
||
| 72 | break; |
||
| 73 | } |
||
| 74 | } |
||
| 75 | } |
||
| 76 | |||
| 77 | switch ($fieldtype) { |
||
| 78 | case 'textbox': |
||
| 79 | if ($custom == '1') { |
||
| 80 | $form_text_tray = new XoopsFormElementTray($title, '', $name); |
||
| 81 | $form_text_tray->addElement(new XoopsFormLabel('', '<table><tr><td>')); |
||
| 82 | $form_text_tray->addElement(new XoopsFormText('<b>' . _MD_CUSTOM_TITLE . '</b></td><td>', 'custom' . $name, 50, 250, $customtitle)); |
||
| 83 | $form_text_tray->addElement(new XoopsFormLabel('', '</td></tr><tr><td>')); |
||
| 84 | $form_text_tray->addElement(new XoopsFormText('<b>' . _MD_CUSTOM_VALUE . '</b></td><td>', $name, $size, $maxsize, $value)); |
||
| 85 | $form_text_tray->addElement(new XoopsFormLabel('', '</td></tr></table>')); |
||
| 86 | $form->addElement($form_text_tray); |
||
| 87 | } else { |
||
| 88 | $form->addElement(new XoopsFormText($title, $name, 50, 250, $myts->htmlSpecialChars($value))); |
||
| 89 | } |
||
| 90 | break; |
||
| 91 | View Code Duplication | case 'textarea': |
|
| 92 | if ($custom == '1') { |
||
| 93 | $form_textarea_tray = new XoopsFormElementTray($title, '', $name); |
||
| 94 | $form_textarea_tray->addElement(new XoopsFormLabel('', '<table><tr><td>')); |
||
| 95 | $form_textarea_tray->addElement(new XoopsFormText('<b>' . _MD_CUSTOM_TITLE . '</b></td><td>', 'custom' . $name, 50, 250, $customtitle)); |
||
| 96 | $form_textarea_tray->addElement(new XoopsFormLabel('', '</td></tr><tr><td>')); |
||
| 97 | $form_textarea_tray->addElement(new XoopsFormTextArea('<b>' . _MD_CUSTOM_VALUE . '</b></td><td>', $name, $value, $rows, $cols)); |
||
| 98 | $form_textarea_tray->addElement(new XoopsFormLabel('', '</td></tr></table>')); |
||
| 99 | $form->addElement($form_textarea_tray); |
||
| 100 | } else { |
||
| 101 | $form->addElement(new XoopsFormTextArea($title, $name, $value, $rows, $cols)); |
||
| 102 | } |
||
| 103 | break; |
||
| 104 | case 'yesno': |
||
| 105 | $form->addElement(new XoopsFormRadioyn($title, $name, $value, _YES, _NO)); |
||
| 106 | break; |
||
| 107 | View Code Duplication | case 'radio': |
|
| 108 | $options_arr = explode('[|]', $options); |
||
| 109 | $form_radio = new XoopsFormRadio($title, $name, $value, 1); |
||
| 110 | foreach ($options_arr as $option) { |
||
| 111 | $form_radio->addOption($option, $option); |
||
| 112 | } |
||
| 113 | $form->addElement($form_radio); |
||
| 114 | break; |
||
| 115 | View Code Duplication | case 'checkbox': |
|
| 116 | $options_arr = explode('[|]', $options); |
||
| 117 | $form_checkbox = new XoopsFormCheckbox($title, $name, $value, 1); |
||
| 118 | foreach ($options_arr as $option) { |
||
| 119 | $form_checkbox->addOption($option, $option); |
||
| 120 | } |
||
| 121 | $form->addElement($form_checkbox); |
||
| 122 | break; |
||
| 123 | case 'select': |
||
| 124 | $options_arr = explode('[|]', $options); |
||
| 125 | $value_arr = explode('[|]', $value); |
||
| 126 | $form_select = new XoopsFormSelect($title, $name, $value, $size, $multiple); |
||
| 127 | $form_select->addOption('-', '----'); |
||
| 128 | $form_select->setValue($value_arr); |
||
| 129 | foreach ($options_arr as $key => $option) { |
||
| 130 | $form_select->addOption($option, $option); |
||
| 131 | } |
||
| 132 | $form->addElement($form_select); |
||
| 133 | break; |
||
| 134 | View Code Duplication | case 'dhtml': |
|
| 135 | if ($custom == '1') { |
||
| 136 | $form_dhtmlarea_tray = new XoopsFormElementTray($title, '', $name); |
||
| 137 | $form_dhtmlarea_tray->addElement(new XoopsFormLabel('', '<table><tr><td>')); |
||
| 138 | $form_dhtmlarea_tray->addElement(new XoopsFormText('<b>' . _MD_CUSTOM_TITLE . '</b></td><td>', 'custom' . $name, 50, 250, $customtitle)); |
||
| 139 | $form_dhtmlarea_tray->addElement(new XoopsFormLabel('', '</td></tr><tr><td>')); |
||
| 140 | $form_dhtmlarea_tray->addElement(new XoopsFormDhtmlTextArea('<b>' . _MD_CUSTOM_VALUE . '</b></td><td>', $name, $value, $rows, $cols)); |
||
| 141 | $form_dhtmlarea_tray->addElement(new XoopsFormLabel('', '</td></tr></table>')); |
||
| 142 | $form->addElement($form_dhtmlarea_tray); |
||
| 143 | } else { |
||
| 144 | $form->addElement(new XoopsFormDhtmlTextArea($title, $name, $value, $rows, $cols)); |
||
| 145 | } |
||
| 146 | break; |
||
| 147 | case 'address': |
||
| 148 | //Query all address fields associated with the address type that belongs to the locid. |
||
| 149 | $addressfields = getAddressFields('0'); |
||
| 150 | $addressvalues = getAddressValues($value); |
||
| 151 | $form->addElement(new XoopsFormLabel('', '<strong>' . $title . '</strong>')); |
||
| 152 | $fieldtitles = array( |
||
| 153 | 'address' => _MD_DF_ADDRESS, |
||
| 154 | 'address2' => _MD_DF_ADDRESS2, |
||
| 155 | 'zip' => _MD_DF_ZIP, |
||
| 156 | 'postcode' => _MD_DF_POSTCODE, |
||
| 157 | 'lat' => _MD_DF_LAT, |
||
| 158 | 'lon' => _MD_DF_LON, |
||
| 159 | 'phone' => _MD_DF_PHONE, |
||
| 160 | 'fax' => _MD_DF_FAX, |
||
| 161 | 'mobile' => _MD_DF_MOBILE, |
||
| 162 | 'city' => _MD_DF_CITY, |
||
| 163 | 'country' => _MD_DF_COUNTRY, |
||
| 164 | 'typename' => _MD_DF_TYPENAME, |
||
| 165 | 'uselocyn' => _MD_DF_USELOCYN |
||
| 166 | ); |
||
| 167 | foreach ($addressfields['addressfields'] as $field => $fieldvalue) { |
||
| 168 | $storedvalue = $addressvalues["$field"]; |
||
| 169 | if ($fieldvalue == 1) { |
||
| 170 | $title = $fieldtitles["$field"]; |
||
| 171 | $form->addElement(new XoopsFormText($title, $name . $field, 50, 250, $myts->htmlSpecialChars($storedvalue))); |
||
| 172 | } |
||
| 173 | } |
||
| 174 | $form->addElement(new XoopsFormHidden('submitaddress', '1')); |
||
| 175 | $form->addElement(new XoopsFormHidden($name, $value)); |
||
| 176 | $form->addElement(new XoopsFormHidden('addrid', $value)); |
||
| 177 | break; |
||
| 178 | case 'rating': |
||
| 179 | $rating_options = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); |
||
| 180 | $form_rating = new XoopsFormSelect($title, $name, $value, 1); |
||
| 181 | $form_rating->addOption('0', '----'); |
||
| 182 | foreach ($rating_options as $option) { |
||
| 183 | $form_rating->addOption($option, $option); |
||
| 184 | } |
||
| 185 | $form->addElement($form_rating); |
||
| 186 | break; |
||
| 187 | case 'date': |
||
| 188 | $form->addElement(new XoopsFormText($title, $name, 10, 10, $value)); |
||
| 189 | break; |
||
| 190 | case 'url': |
||
| 191 | if ($value != '') { |
||
| 192 | $link = explode('|', $value); |
||
| 193 | } else { |
||
| 194 | $link = array(); |
||
| 195 | $link[0] = ''; |
||
| 196 | $link[1] = ''; |
||
| 197 | } |
||
| 198 | $form_textarea_tray = new XoopsFormElementTray($title, '', $name); |
||
| 199 | $form_textarea_tray->addElement(new XoopsFormLabel('', '<table><tr><td>')); |
||
| 200 | $form_textarea_tray->addElement(new XoopsFormText('<b>' . _MD_FIELDNAMES_URL_TITLE . '</b></td><td>', 'url_title' . $name, 50, 250, $link[1])); |
||
| 201 | $form_textarea_tray->addElement(new XoopsFormLabel('', '</td></tr><tr><td>')); |
||
| 202 | $form_textarea_tray->addElement(new XoopsFormText('<b>' . _MD_FIELDNAMES_URL_LINK . '</b></td><td>', 'url_link' . $name, 50, 250, $link[0])); |
||
| 203 | $form_textarea_tray->addElement(new XoopsFormLabel('', '</td></tr></table>')); |
||
| 204 | $form->addElement($form_textarea_tray); |
||
| 205 | break; |
||
| 206 | default: |
||
| 207 | echo $fieldtype . ' is an unknown field type.'; |
||
| 208 | break; |
||
| 209 | } |
||
| 643 |
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