| Conditions | 5 |
| Paths | 16 |
| Total Lines | 110 |
| Code Lines | 57 |
| 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 |
||
| 51 | public function __construct() |
||
| 52 | { |
||
| 53 | $this->config = \XoopsModules\Xooghost\Preferences::getInstance()->loadConfig(); |
||
| 54 | |||
| 55 | extract($this->config); |
||
| 56 | parent::__construct('', 'form_preferences', 'preferences.php', 'post', true); |
||
| 57 | $this->setExtra('enctype="multipart/form-data"'); |
||
| 58 | |||
| 59 | $tabTray = new \Xoops\Form\TabTray('', 'uniqueid'); |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Main page |
||
| 63 | */ |
||
| 64 | $tab1 = new \Xoops\Form\Tab(_XOO_CONFIG_MAINPAGE, 'tabid-1'); |
||
| 65 | //xooghost_main |
||
| 66 | $tab1->addElement(new \Xoops\Form\RadioYesNo(_XOO_CONFIG_MAIN, 'xooghost_main', $xooghost_main)); |
||
| 67 | |||
| 68 | //xooghost_welcome |
||
| 69 | $tab1->addElement(new \Xoops\Form\TextArea(_XOO_CONFIG_WELCOME, 'xooghost_welcome', $xooghost_welcome, 12, 12)); |
||
| 70 | |||
| 71 | //xooghost_main_mode |
||
| 72 | $main_mode = new \Xoops\Form\Select(_XOO_CONFIG_MAIN_MODE, 'xooghost_main_mode', $xooghost_main_mode, $size = 1); |
||
| 73 | $main_mode->addOption('blog', _XOO_CONFIG_MAIN_MODE_BLOG); |
||
| 74 | $main_mode->addOption('list', _XOO_CONFIG_MAIN_MODE_LIST); |
||
| 75 | $main_mode->addOption('select', _XOO_CONFIG_MAIN_MODE_SELECT); |
||
| 76 | $main_mode->addOption('table', _XOO_CONFIG_MAIN_MODE_TABLE); |
||
| 77 | $tab1->addElement($main_mode); |
||
| 78 | |||
| 79 | // limit per page |
||
| 80 | $tab1->addElement(new \Xoops\Form\Text(_XOO_CONFIG_LIMIT_MAIN, 'xooghost_limit_main', 1, 10, $xooghost_limit_main)); |
||
| 81 | |||
| 82 | // date format |
||
| 83 | $main_mode = new \Xoops\Form\Select(_XOO_CONFIG_DATE_FORMAT, 'xooghost_date_format', $xooghost_date_format, $size = 1); |
||
| 84 | |||
| 85 | try { |
||
| 86 | $main_mode->addOption('_DATESTRING', \Xoops\Core\Locale\Time::formatDateTime(new \DateTime('now'), 'long')); |
||
| 87 | } catch (\Exception $e) { |
||
| 88 | } |
||
| 89 | |||
| 90 | try { |
||
| 91 | $main_mode->addOption('_MEDIUMDATESTRING', \Xoops\Core\Locale\Time::formatDateTime(new \DateTime('now'), 'medium')); |
||
| 92 | } catch (\Exception $e) { |
||
| 93 | } |
||
| 94 | |||
| 95 | try { |
||
| 96 | $main_mode->addOption('_SHORTDATESTRING', \Xoops\Core\Locale\Time::formatDateTime(new \DateTime('now'), 'short')); |
||
| 97 | } catch (\Exception $e) { |
||
| 98 | } |
||
| 99 | |||
| 100 | $tab1->addElement($main_mode); |
||
| 101 | |||
| 102 | $tabTray->addElement($tab1); |
||
| 103 | |||
| 104 | /** |
||
| 105 | * Images |
||
| 106 | */ |
||
| 107 | $tab2 = new \Xoops\Form\Tab(_XOO_CONFIG_IMAGE, 'tabid-2'); |
||
| 108 | // xooghost_image_size |
||
| 109 | $tab2->addElement(new \Xoops\Form\Text(_XOO_GHOST_CONFIG_IMAGE_SIZE, 'xooghost_image_size', 1, 10, $xooghost_image_size)); |
||
| 110 | |||
| 111 | // xooghost_image_width |
||
| 112 | $tab2->addElement(new \Xoops\Form\Text(_XOO_GHOST_CONFIG_IMAGE_WIDTH, 'xooghost_image_width', 1, 10, $xooghost_image_width)); |
||
| 113 | |||
| 114 | // xooghost_image_height |
||
| 115 | $tab2->addElement(new \Xoops\Form\Text(_XOO_GHOST_CONFIG_IMAGE_HEIGHT, 'xooghost_image_height', 1, 10, $xooghost_image_height)); |
||
| 116 | |||
| 117 | $tabTray->addElement($tab2); |
||
| 118 | |||
| 119 | /** |
||
| 120 | * Rate / Like - Dislike |
||
| 121 | */ |
||
| 122 | $rld = new \Xoops\Form\Tab(_XOO_CONFIG_RLD, 'tabid-rld'); |
||
| 123 | |||
| 124 | // Rate / Like / Dislike Mode |
||
| 125 | $rld_mode = new \Xoops\Form\Select(_XOO_CONFIG_RLD_MODE, 'xooghost_rld[rld_mode]', $xooghost_rld['rld_mode']); |
||
| 126 | $rld_mode->addOption('none', _XOO_CONFIG_RLD_NONE); |
||
| 127 | $rld_mode->addOption('rate', _XOO_CONFIG_RLD_RATE); |
||
| 128 | $rld_mode->addOption('likedislike', _XOO_CONFIG_RLD_LIKEDISLIKE); |
||
| 129 | $rld->addElement($rld_mode); |
||
| 130 | |||
| 131 | $rate_scale = new \Xoops\Form\Select(_XOO_CONFIG_RATE_SCALE, 'xooghost_rld[rate_scale]', $xooghost_rld['rate_scale']); |
||
| 132 | for ($i = 4; $i <= 10; ++$i) { |
||
| 133 | $rate_scale->addOption($i, $i); |
||
| 134 | } |
||
| 135 | $rld->addElement($rate_scale); |
||
| 136 | |||
| 137 | $tabTray->addElement($rld); |
||
| 138 | |||
| 139 | $this->addElement($tabTray); |
||
| 140 | |||
| 141 | /** |
||
| 142 | * Buttons |
||
| 143 | */ |
||
| 144 | $buttonTray = new \Xoops\Form\ElementTray('', ''); |
||
| 145 | $buttonTray->addElement(new \Xoops\Form\Hidden('op', 'save')); |
||
| 146 | |||
| 147 | $buttonSubmit = new \Xoops\Form\Button('', 'submit', \XoopsLocale::A_SUBMIT, 'submit'); |
||
| 148 | $buttonSubmit->setClass('btn btn-success'); |
||
| 149 | $buttonTray->addElement($buttonSubmit); |
||
| 150 | |||
| 151 | $buttonReset = new \Xoops\Form\Button('', 'reset', \XoopsLocale::A_RESET, 'reset'); |
||
| 152 | $buttonReset->setClass('btn btn-warning'); |
||
| 153 | $buttonTray->addElement($buttonReset); |
||
| 154 | |||
| 155 | $buttonCancel = new \Xoops\Form\Button('', 'cancel', \XoopsLocale::A_CANCEL, 'button'); |
||
| 156 | $buttonCancel->setExtra("onclick='javascript:history.go(-1);'"); |
||
| 157 | $buttonCancel->setClass('btn btn-danger'); |
||
| 158 | $buttonTray->addElement($buttonCancel); |
||
| 159 | |||
| 160 | $this->addElement($buttonTray); |
||
| 161 | } |
||
| 163 |