| Conditions | 13 |
| Paths | 50 |
| Total Lines | 57 |
| Code Lines | 40 |
| Lines | 8 |
| Ratio | 14.04 % |
| 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 |
||
| 39 | public function doInit() |
||
|
|
|||
| 40 | { |
||
| 41 | parent::doInit(); |
||
| 42 | |||
| 43 | $this->startEvent = 'core.index.start'; |
||
| 44 | |||
| 45 | //check if start page is defined |
||
| 46 | $startpage = $this->xoops->getConfig('startpage'); |
||
| 47 | if ($this->xoops->isActiveModule($startpage)) { |
||
| 48 | // Temporary solution for start page redirection |
||
| 49 | define('XOOPS_STARTPAGE_REDIRECTED', 1); |
||
| 50 | $module_handler = $this->xoops->getHandlerModule(); |
||
| 51 | $this->xoops->module = $this->xoops->getModuleByDirname($startpage); |
||
| 52 | if (!$this->xoops->isModule() || !$this->xoops->module->getVar('isactive')) { |
||
| 53 | $this->xoops->header(); |
||
| 54 | echo "<h4>" . XoopsLocale::E_NO_MODULE . "</h4>"; |
||
| 55 | $this->xoops->footer(); |
||
| 56 | exit; |
||
| 57 | } |
||
| 58 | $moduleperm_handler = $this->xoops->getHandlerGroupPermission(); |
||
| 59 | $mid = $this->xoops->module->getVar('mid'); |
||
| 60 | if ($this->xoops->isUser()) { |
||
| 61 | if (!$moduleperm_handler->checkRight('module_read', $mid, $this->xoops->user->getGroups())) { |
||
| 62 | $this->xoops->redirect($this->xoops_url, 1, XoopsLocale::E_NO_ACCESS_PERMISSION, false); |
||
| 63 | } |
||
| 64 | $this->xoops->userIsAdmin = $this->xoops->user->isAdmin($mid); |
||
| 65 | } else { |
||
| 66 | if (!$moduleperm_handler->checkRight('module_read', $mid, FixedGroups::ANONYMOUS)) { |
||
| 67 | $this->xoops->redirect($this->xoops_url . "/user.php", 1, XoopsLocale::E_NO_ACCESS_PERMISSION); |
||
| 68 | } |
||
| 69 | } |
||
| 70 | if ($this->xoops->module->getVar('hasconfig') == 1 |
||
| 71 | || $this->xoops->module->getVar('hascomments') == 1 |
||
| 72 | || $this->xoops->module->getVar('hasnotification') == 1 |
||
| 73 | ) { |
||
| 74 | $this->xoops->moduleConfig = $this->xoops->getModuleConfigs(); |
||
| 75 | } |
||
| 76 | |||
| 77 | chdir('modules/' . $startpage . '/'); |
||
| 78 | $this->xoops->loadLanguage('main', $this->xoops->module->getVar('dirname', 'n')); |
||
| 79 | $parsed = parse_url($this->xoops_url); |
||
| 80 | $url = isset($parsed['scheme']) ? $parsed['scheme'] . '://' : 'http://'; |
||
| 81 | View Code Duplication | if (isset($parsed['host'])) { |
|
| 82 | $url .= $parsed['host']; |
||
| 83 | if (isset($parsed['port'])) { |
||
| 84 | $url .= ':' . $parsed['port']; |
||
| 85 | } |
||
| 86 | } else { |
||
| 87 | $url .= $_SERVER['HTTP_HOST']; |
||
| 88 | } |
||
| 89 | |||
| 90 | $_SERVER['REQUEST_URI'] = |
||
| 91 | substr($this->xoops_url, strlen($url)) . '/modules/' . $startpage . '/index.php'; |
||
| 92 | include $this->xoops->path('modules/' . $startpage . '/index.php'); |
||
| 93 | exit; |
||
| 94 | } |
||
| 95 | } |
||
| 96 | |||
| 107 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: