| Conditions | 2 |
| Paths | 2 |
| Total Lines | 60 |
| Code Lines | 39 |
| 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 |
||
| 45 | public function __construct(Publisher\File $obj) |
||
| 46 | { |
||
| 47 | $xoops = Xoops::getInstance(); |
||
| 48 | $helper = Helper::getInstance(); |
||
| 49 | $helper->loadLanguage('main'); |
||
| 50 | |||
| 51 | parent::__construct(_AM_PUBLISHER_UPLOAD_FILE, 'form', $xoops->getEnv('PHP_SELF')); |
||
| 52 | $this->setExtra('enctype="multipart/form-data"'); |
||
| 53 | |||
| 54 | // NAME |
||
| 55 | $name_text = new Text(_CO_PUBLISHER_FILENAME, 'name', 50, 255, $obj->getVar('name')); |
||
|
|
|||
| 56 | $name_text->setDescription(_CO_PUBLISHER_FILE_NAME_DSC); |
||
| 57 | $this->addElement($name_text, true); |
||
| 58 | |||
| 59 | // DESCRIPTION |
||
| 60 | $description_text = new TextArea(_CO_PUBLISHER_FILE_DESCRIPTION, 'description', $obj->getVar('description')); |
||
| 61 | $description_text->setDescription(_CO_PUBLISHER_FILE_DESCRIPTION_DSC); |
||
| 62 | $this->addElement($description_text); |
||
| 63 | |||
| 64 | // FILE TO UPLOAD |
||
| 65 | $file_box = new File(_CO_PUBLISHER_FILE_TO_UPLOAD, 'item_upload_file'); |
||
| 66 | $file_box->set('size', 50); |
||
| 67 | $this->addElement($file_box); |
||
| 68 | |||
| 69 | $status_select = new RadioYesNo(_CO_PUBLISHER_FILE_STATUS, 'file_status', _PUBLISHER_STATUS_FILE_ACTIVE); |
||
| 70 | $status_select->setDescription(_CO_PUBLISHER_FILE_STATUS_DSC); |
||
| 71 | $this->addElement($status_select); |
||
| 72 | |||
| 73 | // fileid |
||
| 74 | $this->addElement(new Hidden('fileid', $obj->getVar('fileid'))); |
||
| 75 | |||
| 76 | // itemid |
||
| 77 | $this->addElement(new Hidden('itemid', $obj->getVar('itemid'))); |
||
| 78 | |||
| 79 | $files_button_tray = new ElementTray('', ''); |
||
| 80 | $files_hidden = new Hidden('op', 'uploadfile'); |
||
| 81 | $files_button_tray->addElement($files_hidden); |
||
| 82 | |||
| 83 | if (!$obj->getVar('fileid')) { |
||
| 84 | $files_butt_create = new Button('', '', _MD_PUBLISHER_UPLOAD, 'submit'); |
||
| 85 | $files_butt_create->setExtra('onclick="this.form.elements.op.value=\'uploadfile\'"'); |
||
| 86 | $files_button_tray->addElement($files_butt_create); |
||
| 87 | |||
| 88 | $files_butt_another = new Button('', '', _CO_PUBLISHER_FILE_UPLOAD_ANOTHER, 'submit'); |
||
| 89 | $files_butt_another->setExtra('onclick="this.form.elements.op.value=\'uploadanother\'"'); |
||
| 90 | $files_button_tray->addElement($files_butt_another); |
||
| 91 | } else { |
||
| 92 | $files_butt_create = new Button('', '', _MD_PUBLISHER_MODIFY, 'submit'); |
||
| 93 | $files_butt_create->setExtra('onclick="this.form.elements.op.value=\'modify\'"'); |
||
| 94 | $files_button_tray->addElement($files_butt_create); |
||
| 95 | } |
||
| 96 | |||
| 97 | $files_butt_clear = new Button('', '', _MD_PUBLISHER_CLEAR, 'reset'); |
||
| 98 | $files_button_tray->addElement($files_butt_clear); |
||
| 99 | |||
| 100 | $buttonCancel = new Button('', '', _MD_PUBLISHER_CANCEL, 'button'); |
||
| 101 | $buttonCancel->setExtra('onclick="history.go(-1)"'); |
||
| 102 | $files_button_tray->addElement($buttonCancel); |
||
| 103 | |||
| 104 | $this->addElement($files_button_tray); |
||
| 105 | } |
||
| 107 |