| Conditions | 9 |
| Paths | 30 |
| Total Lines | 278 |
| Code Lines | 171 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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:
| 1 | <?php |
||
| 59 | public function __construct($target) |
||
| 60 | { |
||
| 61 | // global $helper; |
||
| 62 | $this->helper = $target->helper; |
||
| 63 | $this->targetObject = $target; |
||
| 64 | $title = $this->targetObject->isNew() ? \sprintf(\AM_ADSLIGHT_LISTING_ADD) : \sprintf(\AM_ADSLIGHT_LISTING_EDIT); |
||
| 65 | parent::__construct($title, 'form', \xoops_getenv('SCRIPT_NAME'), 'post', true); |
||
| 66 | $this->setExtra('enctype="multipart/form-data"'); |
||
| 67 | //include ID field, it's needed so the module knows if it is a new form or an edited form |
||
| 68 | $hidden = new \XoopsFormHidden( |
||
| 69 | 'lid', $this->targetObject->getVar( |
||
| 70 | 'lid' |
||
| 71 | ) |
||
| 72 | ); |
||
| 73 | $this->addElement($hidden); |
||
| 74 | unset($hidden); |
||
| 75 | // Lid |
||
| 76 | $this->addElement( |
||
| 77 | new \XoopsFormLabel(\AM_ADSLIGHT_LISTING_LID, $this->targetObject->getVar('lid'), 'lid') |
||
| 78 | ); |
||
| 79 | // Cid |
||
| 80 | // $this->addElement( |
||
| 81 | // new \XoopsFormText(AM_ADSLIGHT_LISTING_CID, 'cid', 50, 255, $this->targetObject->getVar('cid')), |
||
| 82 | // false |
||
| 83 | // ); |
||
| 84 | |||
| 85 | //$categoriesHandler = $this->helper->getHandler('Categories'); |
||
| 86 | //$db = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 87 | /** @var \XoopsPersistableObjectHandler $categoriesHandler */ |
||
| 88 | $categoriesHandler = $this->helper->getHandler('Categories'); |
||
| 89 | |||
| 90 | $categories_id_select = new \XoopsFormSelect(\AM_ADSLIGHT_LISTING_CID, 'cid', $this->targetObject->getVar('cid')); |
||
| 91 | $categories_id_select->addOptionArray($categoriesHandler->getList()); |
||
| 92 | $this->addElement($categories_id_select, false); |
||
| 93 | |||
| 94 | // Title |
||
| 95 | $this->addElement( |
||
| 96 | new \XoopsFormText(\AM_ADSLIGHT_LISTING_TITLE, 'title', 50, 255, $this->targetObject->getVar('title')), |
||
| 97 | false |
||
| 98 | ); |
||
| 99 | // Status |
||
| 100 | $this->addElement( |
||
| 101 | new \XoopsFormText(\AM_ADSLIGHT_LISTING_STATUS, 'status', 50, 255, $this->targetObject->getVar('status')), |
||
| 102 | false |
||
| 103 | ); |
||
| 104 | // Expire |
||
| 105 | $this->addElement( |
||
| 106 | new \XoopsFormText(\AM_ADSLIGHT_LISTING_EXPIRE, 'expire', 50, 255, $this->targetObject->getVar('expire')), |
||
| 107 | false |
||
| 108 | ); |
||
| 109 | // Type |
||
| 110 | //$typeHandler = $this->helper->getHandler('Type'); |
||
| 111 | $db = XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 112 | $typeHandler = new TypeHandler($db); |
||
| 113 | $type_id_select = new \XoopsFormSelect(\AM_ADSLIGHT_LISTING_TYPE, 'type', $this->targetObject->getVar('type')); |
||
| 114 | $type_id_select->addOptionArray($typeHandler->getList()); |
||
| 115 | $this->addElement($type_id_select, false); |
||
| 116 | // Desctext |
||
| 117 | if (\class_exists('XoopsFormEditor')) { |
||
| 118 | $editorOptions = []; |
||
| 119 | $editorOptions['name'] = 'desctext'; |
||
| 120 | $editorOptions['value'] = $this->targetObject->getVar('desctext', 'e'); |
||
| 121 | $editorOptions['rows'] = 5; |
||
| 122 | $editorOptions['cols'] = 40; |
||
| 123 | $editorOptions['width'] = '100%'; |
||
| 124 | $editorOptions['height'] = '400px'; |
||
| 125 | //$editorOptions['editor'] = xoops_getModuleOption('adslight_editor', 'adslight'); |
||
| 126 | //$this->addElement( new \XoopsFormEditor(AM_ADSLIGHT_LISTING_DESCTEXT, 'desctext', $editorOptions), false ); |
||
| 127 | if ($this->helper->isUserAdmin()) { |
||
| 128 | $descEditor = new \XoopsFormEditor( |
||
| 129 | \AM_ADSLIGHT_LISTING_DESCTEXT, $this->helper->getConfig( |
||
| 130 | 'adslightEditorAdmin' |
||
| 131 | ), $editorOptions, $nohtml = false, $onfailure = 'textarea' |
||
| 132 | ); |
||
| 133 | } else { |
||
| 134 | $descEditor = new \XoopsFormEditor( |
||
| 135 | \AM_ADSLIGHT_LISTING_DESCTEXT, $this->helper->getConfig( |
||
| 136 | 'adslightEditorUser' |
||
| 137 | ), $editorOptions, $nohtml = false, $onfailure = 'textarea' |
||
| 138 | ); |
||
| 139 | } |
||
| 140 | } else { |
||
| 141 | $descEditor = new \XoopsFormDhtmlTextArea( |
||
| 142 | \AM_ADSLIGHT_LISTING_DESCTEXT, 'description', $this->targetObject->getVar( |
||
| 143 | 'description', |
||
| 144 | 'e' |
||
| 145 | ), '100%', '100%' |
||
| 146 | ); |
||
| 147 | } |
||
| 148 | $this->addElement($descEditor); |
||
| 149 | // Tel |
||
| 150 | $this->addElement( |
||
| 151 | new \XoopsFormText(\AM_ADSLIGHT_LISTING_TEL, 'tel', 50, 255, $this->targetObject->getVar('tel')), |
||
| 152 | false |
||
| 153 | ); |
||
| 154 | // Price |
||
| 155 | $this->addElement( |
||
| 156 | new \XoopsFormText(\AM_ADSLIGHT_LISTING_PRICE, 'price', 50, 255, $this->targetObject->getVar('price')), |
||
| 157 | false |
||
| 158 | ); |
||
| 159 | // Typeprice |
||
| 160 | $this->addElement( |
||
| 161 | new \XoopsFormText( |
||
| 162 | \AM_ADSLIGHT_LISTING_TYPEPRICE, 'typeprice', 50, 255, $this->targetObject->getVar( |
||
| 163 | 'typeprice' |
||
| 164 | ) |
||
| 165 | ), |
||
| 166 | false |
||
| 167 | ); |
||
| 168 | // Typecondition |
||
| 169 | $this->addElement( |
||
| 170 | new \XoopsFormText( |
||
| 171 | \AM_ADSLIGHT_LISTING_TYPEUSER, 'typecondition', 50, 255, $this->targetObject->getVar( |
||
| 172 | 'typecondition' |
||
| 173 | ) |
||
| 174 | ), |
||
| 175 | false |
||
| 176 | ); |
||
| 177 | // Date |
||
| 178 | $this->addElement( |
||
| 179 | new \XoopsFormTextDateSelect( |
||
| 180 | \AM_ADSLIGHT_LISTING_DATE, 'date_created', 0, \formatTimestamp($this->targetObject->getVar('date_created'), 's') |
||
| 181 | ) |
||
| 182 | ); |
||
| 183 | |||
| 184 | $this->addElement( |
||
| 185 | new \XoopsFormText(\AM_ADSLIGHT_LISTING_EMAIL, 'email', 50, 255, $this->targetObject->getVar('email')), |
||
| 186 | false |
||
| 187 | ); |
||
| 188 | // Submitter |
||
| 189 | $this->addElement( |
||
| 190 | new \XoopsFormText( |
||
| 191 | \AM_ADSLIGHT_LISTING_SUBMITTER, 'submitter', 50, 255, $this->targetObject->getVar( |
||
| 192 | 'submitter' |
||
| 193 | ) |
||
| 194 | ), |
||
| 195 | false |
||
| 196 | ); |
||
| 197 | // Usid |
||
| 198 | $this->addElement( |
||
| 199 | new \XoopsFormSelectUser( |
||
| 200 | \AM_ADSLIGHT_LISTING_USID, 'usid', false, $this->targetObject->getVar( |
||
| 201 | 'usid' |
||
| 202 | ), 1, false |
||
| 203 | ), |
||
| 204 | false |
||
| 205 | ); |
||
| 206 | // Town |
||
| 207 | $this->addElement( |
||
| 208 | new \XoopsFormText(\AM_ADSLIGHT_LISTING_TOWN, 'town', 50, 255, $this->targetObject->getVar('town')), |
||
| 209 | false |
||
| 210 | ); |
||
| 211 | // Country |
||
| 212 | $country = new \XoopsFormSelect( |
||
| 213 | \AM_ADSLIGHT_LISTING_COUNTRY, 'country', $this->targetObject->getVar( |
||
| 214 | 'country' |
||
| 215 | ) |
||
| 216 | ); |
||
| 217 | $optionsArray = Utility::enumerate('adslight_listing', 'country'); |
||
| 218 | if (!\is_array($optionsArray)) { |
||
| 219 | throw new \RuntimeException($optionsArray . ' must be an array.'); |
||
| 220 | } |
||
| 221 | foreach ($optionsArray as $enum) { |
||
| 222 | $country->addOption($enum, (\defined($enum) ? \constant($enum) : $enum)); |
||
| 223 | } |
||
| 224 | $this->addElement($country, false); |
||
| 225 | // Contactby |
||
| 226 | $this->addElement( |
||
| 227 | new \XoopsFormText( |
||
| 228 | \AM_ADSLIGHT_LISTING_CONTACTBY, 'contactby', 50, 255, $this->targetObject->getVar( |
||
| 229 | 'contactby' |
||
| 230 | ) |
||
| 231 | ), |
||
| 232 | false |
||
| 233 | ); |
||
| 234 | // Premium |
||
| 235 | $this->addElement( |
||
| 236 | new \XoopsFormText( |
||
| 237 | \AM_ADSLIGHT_LISTING_PREMIUM, 'premium', 50, 255, $this->targetObject->getVar( |
||
| 238 | 'premium' |
||
| 239 | ) |
||
| 240 | ), |
||
| 241 | false |
||
| 242 | ); |
||
| 243 | // Valid |
||
| 244 | $this->addElement( |
||
| 245 | new \XoopsFormText(\AM_ADSLIGHT_LISTING_VALID, 'valid', 50, 255, $this->targetObject->getVar('valid')), |
||
| 246 | false |
||
| 247 | ); |
||
| 248 | // Photo |
||
| 249 | $photo = $this->targetObject->getVar('photo') ?: 'blank.png'; |
||
| 250 | $uploadDir = '/uploads/adslight/'; |
||
| 251 | $imgtray = new \XoopsFormElementTray(\AM_ADSLIGHT_LISTING_PHOTO, '<br>'); |
||
| 252 | $imgpath = \sprintf(\AM_ADSLIGHT_FORMIMAGE_PATH, $uploadDir); |
||
| 253 | $imageselect = new \XoopsFormSelect($imgpath, 'photo', $photo); |
||
| 254 | $imageArray = \XoopsLists::getImgListAsArray(XOOPS_ROOT_PATH . $uploadDir); |
||
| 255 | foreach ($imageArray as $image) { |
||
| 256 | $imageselect->addOption($image, $image); |
||
| 257 | } |
||
| 258 | $imageselect->setExtra( |
||
| 259 | "onchange='showImgSelected(\"image_photo\", \"photo\", \"" . $uploadDir . '", "", "' . XOOPS_URL . "\")'" |
||
| 260 | ); |
||
| 261 | $imgtray->addElement($imageselect); |
||
| 262 | $imgtray->addElement( |
||
| 263 | new \XoopsFormLabel( |
||
| 264 | '', "<br><img src='" . XOOPS_URL . '/' . $uploadDir . '/' . $photo . "' name='image_photo' id='image_photo' alt=''>" |
||
| 265 | ) |
||
| 266 | ); |
||
| 267 | $fileseltray = new \XoopsFormElementTray('', '<br>'); |
||
| 268 | $fileseltray->addElement( |
||
| 269 | new \XoopsFormFile(\AM_ADSLIGHT_FORMUPLOAD, 'photo', \xoops_getModuleOption('maxsize')) |
||
| 270 | ); |
||
| 271 | $fileseltray->addElement(new \XoopsFormLabel('')); |
||
| 272 | $imgtray->addElement($fileseltray); |
||
| 273 | $this->addElement($imgtray); |
||
| 274 | // Hits |
||
| 275 | $this->addElement( |
||
| 276 | new \XoopsFormText(\AM_ADSLIGHT_LISTING_HITS, 'hits', 50, 255, $this->targetObject->getVar('hits')), |
||
| 277 | false |
||
| 278 | ); |
||
| 279 | // Item_rating |
||
| 280 | $this->addElement( |
||
| 281 | new \XoopsFormText( |
||
| 282 | \AM_ADSLIGHT_LISTING_ITEM_RATING, 'item_rating', 50, 255, $this->targetObject->getVar( |
||
| 283 | 'item_rating' |
||
| 284 | ) |
||
| 285 | ), |
||
| 286 | false |
||
| 287 | ); |
||
| 288 | // Item_votes |
||
| 289 | //$itemvotedataHandler = $this->helper->getHandler('Itemvotedata'); |
||
| 290 | $db = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 291 | $itemvotedataHandler = new ItemvotedataHandler($db); |
||
| 292 | $itemvotedata_id_select = new \XoopsFormSelect( |
||
| 293 | \AM_ADSLIGHT_LISTING_ITEM_VOTES, 'item_votes', $this->targetObject->getVar( |
||
| 294 | 'item_votes' |
||
| 295 | ) |
||
| 296 | ); |
||
| 297 | $itemvotedata_id_select->addOptionArray($itemvotedataHandler->getList()); |
||
| 298 | $this->addElement($itemvotedata_id_select, false); |
||
| 299 | // User_rating |
||
| 300 | $this->addElement( |
||
| 301 | new \XoopsFormText( |
||
| 302 | \AM_ADSLIGHT_LISTING_USER_RATING, 'user_rating', 50, 255, $this->targetObject->getVar( |
||
| 303 | 'user_rating' |
||
| 304 | ) |
||
| 305 | ), |
||
| 306 | false |
||
| 307 | ); |
||
| 308 | // User_votes |
||
| 309 | //$uservotedataHandler = $this->helper->getHandler('Uservotedata'); |
||
| 310 | $db = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 311 | $uservotedataHandler = new UservotedataHandler( |
||
| 312 | $db |
||
| 313 | ); |
||
| 314 | $uservotedata_id_select = new \XoopsFormSelect( |
||
| 315 | \AM_ADSLIGHT_LISTING_USER_VOTES, 'user_votes', $this->targetObject->getVar( |
||
| 316 | 'user_votes' |
||
| 317 | ) |
||
| 318 | ); |
||
| 319 | $uservotedata_id_select->addOptionArray($uservotedataHandler->getList()); |
||
| 320 | $this->addElement($uservotedata_id_select, false); |
||
| 321 | // Comments |
||
| 322 | $this->addElement( |
||
| 323 | new \XoopsFormText( |
||
| 324 | \AM_ADSLIGHT_LISTING_COMMENTS, 'comments', 50, 255, $this->targetObject->getVar( |
||
| 325 | 'comments' |
||
| 326 | ) |
||
| 327 | ), |
||
| 328 | false |
||
| 329 | ); |
||
| 330 | // Remind |
||
| 331 | $this->addElement( |
||
| 332 | new \XoopsFormText(\AM_ADSLIGHT_LISTING_REMIND, 'remind', 50, 255, $this->targetObject->getVar('remind')), |
||
| 333 | false |
||
| 334 | ); |
||
| 335 | $this->addElement(new \XoopsFormHidden('op', 'save')); |
||
| 336 | $this->addElement(new \XoopsFormButton('', 'submit', \_SUBMIT, 'submit')); |
||
| 337 | } |
||
| 339 |
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