| Conditions | 18 |
| Paths | 288 |
| Total Lines | 98 |
| Code Lines | 65 |
| 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 |
||
| 23 | function protector_onupdate_base($module, $mydirname) |
||
| 24 | { |
||
| 25 | // transations on module update |
||
| 26 | |||
| 27 | global $msgs; // TODO :-D |
||
| 28 | |||
| 29 | // for Cube 2.1 |
||
| 30 | if (defined('XOOPS_CUBE_LEGACY')) { |
||
| 31 | $root =& XCube_Root::getSingleton(); |
||
| 32 | $root->mDelegateManager->add('Legacy.Admin.Event.ModuleUpdate.' . ucfirst($mydirname) . '.Success', 'protector_message_append_onupdate'); |
||
| 33 | $msgs = array(); |
||
| 34 | } else { |
||
| 35 | if (!is_array($msgs)) { |
||
| 36 | $msgs = array(); |
||
| 37 | } |
||
| 38 | } |
||
| 39 | |||
| 40 | $db = XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 41 | $mid = $module->getVar('mid'); |
||
| 42 | |||
| 43 | // TABLES (write here ALTER TABLE etc. if necessary) |
||
| 44 | |||
| 45 | // configs (Though I know it is not a recommended way...) |
||
| 46 | $sql = 'SHOW COLUMNS FROM ' . $db->prefix('config') . " LIKE 'conf_title'"; |
||
| 47 | $result = $db->query($sql); |
||
| 48 | if ($db->isResultSet($result) && ($myrow = $db->fetchArray($result)) && @$myrow['Type'] === 'varchar(30)') { |
||
| 49 | $db->queryF('ALTER TABLE ' . $db->prefix('config') . " MODIFY `conf_title` varchar(255) NOT NULL default '', MODIFY `conf_desc` varchar(255) NOT NULL default ''"); |
||
| 50 | } |
||
| 51 | |||
| 52 | $sql = 'SHOW CREATE TABLE ' . $db->prefix('config'); |
||
| 53 | $result = $db->query($sql); |
||
| 54 | if (!$db->isResultSet($result)) { |
||
| 55 | \trigger_error("Query Failed! SQL: $sql- Error: " . $db->error(), E_USER_ERROR); |
||
| 56 | } |
||
| 57 | list(, $create_string) = $db->fetchRow($result); |
||
| 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 | if (!$db->isResultSet($result)) { |
||
| 70 | \trigger_error("Query Failed! SQL: $sql- Error: " . $db->error(), E_USER_ERROR); |
||
| 71 | } |
||
| 72 | list(, $create_string) = $db->fetchRow($result); |
||
| 73 | if (preg_match('/timestamp\(/i', $create_string)) { |
||
| 74 | $db->query('ALTER TABLE ' . $db->prefix($mydirname . '_log') . ' MODIFY `timestamp` DATETIME'); |
||
| 75 | } |
||
| 76 | |||
| 77 | // TEMPLATES (all templates have been already removed by modulesadmin) |
||
| 78 | $tplfile_handler = xoops_getHandler('tplfile'); |
||
| 79 | $tpl_path = __DIR__ . '/templates'; |
||
| 80 | if ($handler = @opendir($tpl_path . '/')) { |
||
| 81 | while (($file = readdir($handler)) !== false) { |
||
| 82 | if (substr($file, 0, 1) === '.') { |
||
| 83 | continue; |
||
| 84 | } |
||
| 85 | $file_path = $tpl_path . '/' . $file; |
||
| 86 | if (is_file($file_path) && in_array(strrchr($file, '.'), array('.html', '.css', '.js'))) { |
||
| 87 | $mtime = (int)(@filemtime($file_path)); |
||
| 88 | $tplfile = $tplfile_handler->create(); |
||
| 89 | $tplfile->setVar('tpl_source', file_get_contents($file_path), true); |
||
| 90 | $tplfile->setVar('tpl_refid', $mid); |
||
| 91 | $tplfile->setVar('tpl_tplset', 'default'); |
||
| 92 | $tplfile->setVar('tpl_file', $mydirname . '_' . $file); |
||
| 93 | $tplfile->setVar('tpl_desc', '', true); |
||
| 94 | $tplfile->setVar('tpl_module', $mydirname); |
||
| 95 | $tplfile->setVar('tpl_lastmodified', $mtime); |
||
| 96 | $tplfile->setVar('tpl_lastimported', 0); |
||
| 97 | $tplfile->setVar('tpl_type', 'module'); |
||
| 98 | if (!$tplfile_handler->insert($tplfile)) { |
||
| 99 | $msgs[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> to the database.</span>'; |
||
| 100 | } else { |
||
| 101 | $tplid = $tplfile->getVar('tpl_id'); |
||
| 102 | $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> added to the database. (ID: <b>' . $tplid . '</b>)'; |
||
| 103 | // generate compiled file |
||
| 104 | include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php'; |
||
| 105 | include_once XOOPS_ROOT_PATH . '/class/template.php'; |
||
| 106 | if (!xoops_template_touch($tplid)) { |
||
| 107 | $msgs[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b>.</span>'; |
||
| 108 | } else { |
||
| 109 | $msgs[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file) . '</b> compiled.</span>'; |
||
| 110 | } |
||
| 111 | } |
||
| 112 | } |
||
| 113 | } |
||
| 114 | closedir($handler); |
||
| 115 | } |
||
| 116 | include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php'; |
||
| 117 | include_once XOOPS_ROOT_PATH . '/class/template.php'; |
||
| 118 | xoops_template_clear_module_cache($mid); |
||
| 119 | |||
| 120 | return true; |
||
| 121 | } |
||
| 138 |
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.