| Conditions | 5 |
| Paths | 7 |
| Total Lines | 83 |
| Code Lines | 62 |
| 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 |
||
| 125 | function xoops_module_install_newbb(\XoopsModule $module) |
||
| 126 | { |
||
| 127 | /* Create a test category */ |
||
| 128 | /** @var Newbb\CategoryHandler $categoryHandler */ |
||
| 129 | $categoryHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Category'); |
||
| 130 | $category = $categoryHandler->create(); |
||
| 131 | $category->setVar('cat_title', _MI_NEWBB_INSTALL_CAT_TITLE, true); |
||
| 132 | $category->setVar('cat_image', '', true); |
||
| 133 | $category->setVar('cat_description', _MI_NEWBB_INSTALL_CAT_DESC, true); |
||
| 134 | $category->setVar('cat_url', 'https://xoops.org XOOPS Project', true); |
||
| 135 | if (!$cat_id = $categoryHandler->insert($category)) { |
||
| 136 | return true; |
||
| 137 | } |
||
| 138 | |||
| 139 | /* Create a forum for test */ |
||
| 140 | /** @var Newbb\ForumHandler $forumHandler */ |
||
| 141 | $forumHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Forum'); |
||
| 142 | $forum = $forumHandler->create(); |
||
| 143 | $forum->setVar('forum_name', _MI_NEWBB_INSTALL_FORUM_NAME, true); |
||
| 144 | $forum->setVar('forum_desc', _MI_NEWBB_INSTALL_FORUM_DESC, true); |
||
| 145 | $forum->setVar('forum_moderator', []); |
||
| 146 | $forum->setVar('parent_forum', 0); |
||
| 147 | $forum->setVar('cat_id', $cat_id); |
||
| 148 | $forum->setVar('attach_maxkb', 100); |
||
| 149 | $forum->setVar('attach_ext', 'zip|jpg|gif|png'); |
||
| 150 | $forum->setVar('hot_threshold', 20); |
||
| 151 | $forum_id = $forumHandler->insert($forum); |
||
| 152 | |||
| 153 | /* Set corresponding permissions for the category and the forum */ |
||
| 154 | $module_id = $module->getVar('mid'); |
||
| 155 | /** @var \XoopsGroupPermHandler $grouppermHandler */ |
||
| 156 | $grouppermHandler = xoops_getHandler('groupperm'); |
||
| 157 | $groups_view = [XOOPS_GROUP_ADMIN, XOOPS_GROUP_USERS, XOOPS_GROUP_ANONYMOUS]; |
||
| 158 | $groups_post = [XOOPS_GROUP_ADMIN, XOOPS_GROUP_USERS]; |
||
| 159 | // irmtfan bug fix: html and signature permissions, add: pdf and print permissions |
||
| 160 | $post_items = [ |
||
| 161 | 'post', |
||
| 162 | 'reply', |
||
| 163 | 'edit', |
||
| 164 | 'delete', |
||
| 165 | 'addpoll', |
||
| 166 | 'vote', |
||
| 167 | 'attach', |
||
| 168 | 'noapprove', |
||
| 169 | 'type', |
||
| 170 | 'html', |
||
| 171 | 'signature', |
||
| 172 | 'pdf', |
||
| 173 | 'print', |
||
| 174 | ]; |
||
| 175 | foreach ($groups_view as $group_id) { |
||
| 176 | $grouppermHandler->addRight('category_access', $cat_id, $group_id, $module_id); |
||
| 177 | $grouppermHandler->addRight('forum_access', $forum_id, $group_id, $module_id); |
||
| 178 | $grouppermHandler->addRight('forum_view', $forum_id, $group_id, $module_id); |
||
| 179 | } |
||
| 180 | foreach ($groups_post as $group_id) { |
||
| 181 | foreach ($post_items as $item) { |
||
| 182 | $grouppermHandler->addRight('forum_' . $item, $forum_id, $group_id, $module_id); |
||
| 183 | } |
||
| 184 | } |
||
| 185 | |||
| 186 | /* Create a test post */ |
||
| 187 | require_once __DIR__ . '/functions.user.php'; |
||
| 188 | /** @var Newbb\PostHandler $postHandler */ |
||
| 189 | $postHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Post'); |
||
| 190 | /** @var $forumpost */ |
||
| 191 | $forumpost = $postHandler->create(); |
||
| 192 | $forumpost->setVar('poster_ip', \Xmf\IPAddress::fromRequest()->asReadable()); |
||
| 193 | $forumpost->setVar('uid', $GLOBALS['xoopsUser']->getVar('uid')); |
||
| 194 | $forumpost->setVar('approved', 1); |
||
| 195 | $forumpost->setVar('forum_id', $forum_id); |
||
| 196 | $forumpost->setVar('subject', _MI_NEWBB_INSTALL_POST_SUBJECT, true); |
||
| 197 | $forumpost->setVar('dohtml', 1); |
||
| 198 | $forumpost->setVar('dosmiley', 1); |
||
| 199 | $forumpost->setVar('doxcode', 1); |
||
| 200 | $forumpost->setVar('dobr', 1); |
||
| 201 | $forumpost->setVar('icon', '', true); |
||
| 202 | $forumpost->setVar('attachsig', 1); |
||
| 203 | $forumpost->setVar('post_time', time()); |
||
| 204 | $forumpost->setVar('post_text', _MI_NEWBB_INSTALL_POST_TEXT, true); |
||
| 205 | $postid = $postHandler->insert($forumpost); |
||
| 206 | |||
| 207 | return true; |
||
| 208 | } |
||
| 209 |