| Conditions | 24 |
| Paths | 96 |
| Total Lines | 105 |
| Code Lines | 65 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 7 | ||
| Bugs | 3 | Features | 1 |
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 |
||
| 23 | function protector_onupdate_base($module, $mydirname) |
||
| 24 | { |
||
| 25 | // translations on module update |
||
| 26 | |||
| 27 | global $msgs; // TODO :-D |
||
| 28 | |||
| 29 | if (!is_array($msgs)) { |
||
| 30 | $msgs = array(); |
||
| 31 | } |
||
| 32 | |||
| 33 | /** @var XoopsMySQLDatabase $db */ |
||
| 34 | $db = XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 35 | $mid = $module->getVar('mid'); |
||
| 36 | |||
| 37 | // TABLES (write here ALTER TABLE etc. if necessary) |
||
| 38 | |||
| 39 | // configs (Though I know it is not a recommended way...) |
||
| 40 | $sql = 'SHOW COLUMNS FROM ' . $db->prefix('config') . " LIKE 'conf_title'"; |
||
| 41 | $result = $db->query($sql); |
||
| 42 | if ($result !== false && $db->isResultSet($result)) { |
||
| 43 | if ($result instanceof mysqli_result && ($myrow = $db->fetchArray($result)) && isset($myrow['Type']) && $myrow['Type'] === 'varchar(30)') { |
||
| 44 | $db->queryF('ALTER TABLE ' . $db->prefix('config') . " MODIFY `conf_title` varchar(255) NOT NULL default '', MODIFY `conf_desc` varchar(255) NOT NULL default ''"); |
||
| 45 | } |
||
| 46 | } |
||
| 47 | |||
| 48 | $sql = 'SHOW CREATE TABLE ' . $db->prefix('config'); |
||
| 49 | $result = $db->query($sql); |
||
| 50 | if (false === $result || !($result instanceof mysqli_result) || !$db->isResultSet($result)) { |
||
| 51 | throw new \RuntimeException( |
||
| 52 | \sprintf(_DB_QUERY_ERROR, $sql) . $db->error(), E_USER_ERROR |
||
| 53 | ); |
||
| 54 | } else { |
||
| 55 | list(, $create_string) = $db->fetchRow($result); |
||
| 56 | } |
||
| 57 | |||
| 58 | |||
| 59 | foreach (explode('KEY', $create_string) as $line) { |
||
| 60 | if (preg_match('/(\`conf\_title_\d+\`) \(\`conf\_title\`\)/', $line, $regs)) { |
||
| 61 | $db->query('ALTER TABLE ' . $db->prefix('config') . ' DROP KEY ' . $regs[1]); |
||
| 62 | } |
||
| 63 | } |
||
| 64 | $db->query('ALTER TABLE ' . $db->prefix('config') . ' ADD KEY `conf_title` (`conf_title`)'); |
||
| 65 | |||
| 66 | // 2.x -> 3.0 |
||
| 67 | $sql = 'SHOW CREATE TABLE ' . $db->prefix($mydirname . '_log'); |
||
| 68 | $result = $db->query($sql); |
||
| 69 | |||
| 70 | if (false === $result || !($result instanceof mysqli_result) || !$db->isResultSet($result)) { |
||
| 71 | throw new \RuntimeException( |
||
| 72 | \sprintf(_DB_QUERY_ERROR, $sql) . $db->error(), E_USER_ERROR |
||
| 73 | ); |
||
| 74 | } else { |
||
| 75 | list(, $create_string) = $db->fetchRow($result); |
||
| 76 | } |
||
| 77 | |||
| 78 | |||
| 79 | if (preg_match('/timestamp\(/i', $create_string)) { |
||
| 80 | $db->query('ALTER TABLE ' . $db->prefix($mydirname . '_log') . ' MODIFY `timestamp` DATETIME'); |
||
| 81 | } |
||
| 82 | |||
| 83 | // TEMPLATES (all templates have been already removed by modulesadmin) |
||
| 84 | /** @var XoopsTplfileHandler $tplfile_handler */ |
||
| 85 | $tplfile_handler = xoops_getHandler('tplfile'); |
||
| 86 | $tpl_path = __DIR__ . '/templates'; |
||
| 87 | if ($handler = @opendir($tpl_path . '/')) { |
||
| 88 | while (($file = readdir($handler)) !== false) { |
||
| 89 | if (substr($file, 0, 1) === '.') { |
||
| 90 | continue; |
||
| 91 | } |
||
| 92 | $file_path = $tpl_path . '/' . $file; |
||
| 93 | if (is_file($file_path) && in_array(strrchr($file, '.'), array('.html', '.css', '.js'))) { |
||
| 94 | $mtime = (int)(@filemtime($file_path)); |
||
| 95 | $tplfile = $tplfile_handler->create(); |
||
| 96 | $tplfile->setVar('tpl_source', file_get_contents($file_path), true); |
||
| 97 | $tplfile->setVar('tpl_refid', $mid); |
||
| 98 | $tplfile->setVar('tpl_tplset', 'default'); |
||
| 99 | $tplfile->setVar('tpl_file', $mydirname . '_' . $file); |
||
| 100 | $tplfile->setVar('tpl_desc', '', true); |
||
| 101 | $tplfile->setVar('tpl_module', $mydirname); |
||
| 102 | $tplfile->setVar('tpl_lastmodified', $mtime); |
||
| 103 | $tplfile->setVar('tpl_lastimported', 0); |
||
| 104 | $tplfile->setVar('tpl_type', 'module'); |
||
| 105 | if (!$tplfile_handler->insert($tplfile)) { |
||
| 106 | $msgs[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>' . htmlspecialchars($mydirname . '_' . $file, ENT_QUOTES) . '</b> to the database.</span>'; |
||
| 107 | } else { |
||
| 108 | $tplid = $tplfile->getVar('tpl_id'); |
||
| 109 | $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file, ENT_QUOTES) . '</b> added to the database. (ID: <b>' . $tplid . '</b>)'; |
||
| 110 | // generate compiled file |
||
| 111 | include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php'; |
||
| 112 | include_once XOOPS_ROOT_PATH . '/class/template.php'; |
||
| 113 | if (!xoops_template_touch((string)$tplid)) { |
||
| 114 | $msgs[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>' . htmlspecialchars($mydirname . '_' . $file, ENT_QUOTES) . '</b>.</span>'; |
||
| 115 | } else { |
||
| 116 | $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file, ENT_QUOTES) . '</b> compiled.</span>'; |
||
| 117 | } |
||
| 118 | } |
||
| 119 | } |
||
| 120 | } |
||
| 121 | closedir($handler); |
||
| 122 | } |
||
| 123 | include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php'; |
||
| 124 | include_once XOOPS_ROOT_PATH . '/class/template.php'; |
||
| 125 | xoops_template_clear_module_cache($mid); |
||
| 126 | |||
| 127 | return true; |
||
| 128 | } |
||
| 145 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.