| Conditions | 4 |
| Paths | 4 |
| Total Lines | 55 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| 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:
| 1 | <?php namespace XoopsModules\Cardealer\Form; |
||
| 48 | public function __construct($target) |
||
| 49 | { |
||
| 50 | global $helper; |
||
| 51 | $this->targetObject = $target; |
||
| 52 | |||
| 53 | $title = $this->targetObject->isNew() ? sprintf(AM_CARDEALER_VEHICLE_ADD) : sprintf(AM_CARDEALER_VEHICLE_EDIT); |
||
| 54 | parent::__construct($title, 'form', xoops_getenv('PHP_SELF'), 'post', true); |
||
| 55 | $this->setExtra('enctype="multipart/form-data"'); |
||
| 56 | |||
| 57 | //include ID field, it's needed so the module knows if it is a new form or an edited form |
||
| 58 | |||
| 59 | $hidden = new \XoopsFormHidden('id', $this->targetObject->getVar('id')); |
||
| 60 | $this->addElement($hidden); |
||
| 61 | unset($hidden); |
||
| 62 | |||
| 63 | // Id |
||
| 64 | $this->addElement(new \XoopsFormLabel(AM_CARDEALER_VEHICLE_ID, $this->targetObject->getVar('id'), 'id')); |
||
| 65 | // Custnum |
||
| 66 | $db = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 67 | /** @var \XoopsPersistableObjectHandler $customerHandler */ |
||
| 68 | $customerHandler = new cardealer\CustomerHandler($db); |
||
| 69 | |||
| 70 | $customer_id_select = new \XoopsFormSelect(AM_CARDEALER_VEHICLE_CUSTNUM, 'custnum', $this->targetObject->getVar('custnum')); |
||
| 71 | $customer_id_select->addOptionArray($customerHandler->getList()); |
||
| 72 | $this->addElement($customer_id_select, false); |
||
| 73 | // Make |
||
| 74 | $this->addElement(new \XoopsFormText(AM_CARDEALER_VEHICLE_MAKE, 'make', 50, 255, $this->targetObject->getVar('make')), false); |
||
| 75 | // Model |
||
| 76 | $this->addElement(new \XoopsFormText(AM_CARDEALER_VEHICLE_MODEL, 'model', 50, 255, $this->targetObject->getVar('model')), false); |
||
| 77 | // Year |
||
| 78 | $this->addElement(new \XoopsFormText(AM_CARDEALER_VEHICLE_YEAR, 'year', 50, 255, $this->targetObject->getVar('year')), false); |
||
| 79 | // Pictures |
||
| 80 | $pictures = $this->targetObject->getVar('pictures') ?: 'blank.png'; |
||
| 81 | |||
| 82 | $uploadDir = '/uploads/cardealer/images/'; |
||
| 83 | $imgtray = new \XoopsFormElementTray(AM_CARDEALER_VEHICLE_PICTURES, '<br>'); |
||
| 84 | $imgpath = sprintf(AM_CARDEALER_FORMIMAGE_PATH, $uploadDir); |
||
| 85 | $imageselect = new \XoopsFormSelect($imgpath, 'pictures', $pictures); |
||
| 86 | $imageArray = \XoopsLists::getImgListAsArray(XOOPS_ROOT_PATH . $uploadDir); |
||
| 87 | foreach ($imageArray as $image) { |
||
| 88 | $imageselect->addOption((string)$image, $image); |
||
| 89 | } |
||
| 90 | $imageselect->setExtra("onchange='showImgSelected(\"image_pictures\", \"pictures\", \"" . $uploadDir . '", "", "' . XOOPS_URL . "\")'"); |
||
| 91 | $imgtray->addElement($imageselect); |
||
| 92 | $imgtray->addElement(new \XoopsFormLabel('', "<br><img src='" . XOOPS_URL . '/' . $uploadDir . '/' . $pictures . "' name='image_pictures' id='image_pictures' alt='' />")); |
||
| 93 | $fileseltray = new \XoopsFormElementTray('', '<br>'); |
||
| 94 | $fileseltray->addElement(new \XoopsFormFile(AM_CARDEALER_FORMUPLOAD, 'pictures', xoops_getModuleOption('maxsize'))); |
||
| 95 | $fileseltray->addElement(new \XoopsFormLabel('')); |
||
| 96 | $imgtray->addElement($fileseltray); |
||
| 97 | $this->addElement($imgtray); |
||
| 98 | // Serialnum |
||
| 99 | $this->addElement(new \XoopsFormText(AM_CARDEALER_VEHICLE_SERIALNUM, 'serialnum', 50, 255, $this->targetObject->getVar('serialnum')), false); |
||
| 100 | |||
| 101 | $this->addElement(new \XoopsFormHidden('op', 'save')); |
||
| 102 | $this->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit')); |
||
| 103 | } |
||
| 105 |