| Conditions | 16 |
| Paths | 16 |
| Total Lines | 105 |
| Code Lines | 68 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| Bugs | 1 | 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 |
||
| 23 | function protector_oninstall_base($module, $mydirname) |
||
| 24 | { |
||
| 25 | /** @var XoopsModule $module */ |
||
| 26 | // translations on module install |
||
| 27 | |||
| 28 | global $ret; // TODO :-D |
||
| 29 | |||
| 30 | if (!is_array($ret)) { |
||
| 31 | $ret = array(); |
||
| 32 | } |
||
| 33 | |||
| 34 | /** @var XoopsMySQLDatabase $db */ |
||
| 35 | $db = XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 36 | $mid = $module->getVar('mid'); |
||
| 37 | |||
| 38 | // TABLES (loading mysql.sql) |
||
| 39 | $sql_file_path = __DIR__ . '/sql/mysql.sql'; |
||
| 40 | $prefix_mod = $db->prefix() . '_' . $mydirname; |
||
| 41 | if (file_exists($sql_file_path)) { |
||
| 42 | $ret[] = 'SQL file found at <b>' . htmlspecialchars($sql_file_path, ENT_QUOTES) . '</b>.<br> Creating tables...<br>'; |
||
| 43 | |||
| 44 | include_once XOOPS_ROOT_PATH . '/class/database/sqlutility.php'; |
||
| 45 | $sqlutil = new SqlUtility; //old code is -> $sqlutil =& new SqlUtility ; //hack by Trabis |
||
| 46 | |||
| 47 | $sql_query = trim(file_get_contents($sql_file_path)); |
||
| 48 | $sqlutil::splitMySqlFile($pieces, $sql_query); |
||
| 49 | $created_tables = []; |
||
| 50 | foreach ($pieces as $piece) { |
||
| 51 | $prefixed_query = $sqlutil::prefixQuery($piece, $prefix_mod); |
||
| 52 | if (!$prefixed_query) { |
||
| 53 | $ret[] = 'Invalid SQL <b>' . htmlspecialchars($piece, ENT_QUOTES) . '</b><br>'; |
||
| 54 | |||
| 55 | return false; |
||
| 56 | } |
||
| 57 | if (!$db->query($prefixed_query[0])) { |
||
| 58 | $ret[] = '<b>' . htmlspecialchars($db->error(), ENT_QUOTES) . '</b><br>'; |
||
| 59 | |||
| 60 | //var_dump( $db->error() ) ; |
||
| 61 | return false; |
||
| 62 | } else { |
||
| 63 | if (!in_array($prefixed_query[4], $created_tables)) { |
||
| 64 | $ret[] = 'Table <b>' . htmlspecialchars($prefix_mod . '_' . $prefixed_query[4], ENT_QUOTES) . '</b> created.<br>'; |
||
| 65 | $created_tables[] = $prefixed_query[4]; |
||
| 66 | } else { |
||
| 67 | $ret[] = 'Data inserted to table <b>' . htmlspecialchars($prefix_mod . '_' . $prefixed_query[4], ENT_QUOTES) . '</b>.</br />'; |
||
| 68 | } |
||
| 69 | } |
||
| 70 | } |
||
| 71 | } |
||
| 72 | |||
| 73 | // TEMPLATES |
||
| 74 | /** @var XoopsTplfileHandler $tplfile_handler */ |
||
| 75 | $tplfile_handler = xoops_getHandler('tplfile'); |
||
| 76 | $tpl_path = __DIR__ . '/templates'; |
||
| 77 | // Check if the directory exists |
||
| 78 | if (is_dir($tpl_path) && is_readable($tpl_path)) { |
||
| 79 | // Try to open the directory |
||
| 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 | $ret[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>' . htmlspecialchars($mydirname . '_' . $file, ENT_QUOTES) . '</b> to the database.</span><br>'; |
||
| 100 | } else { |
||
| 101 | $tplid = $tplfile->getVar('tpl_id'); |
||
| 102 | $ret[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file, ENT_QUOTES) . '</b> added to the database. (ID: <b>' . $tplid . '</b>)<br>'; |
||
| 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((string)$tplid)) { |
||
| 107 | $ret[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>' . htmlspecialchars($mydirname . '_' . $file, ENT_QUOTES) . '</b>.</span><br>'; |
||
| 108 | } else { |
||
| 109 | $ret[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file, ENT_QUOTES) . '</b> compiled.</span><br>'; |
||
| 110 | } |
||
| 111 | } |
||
| 112 | } |
||
| 113 | } |
||
| 114 | closedir($handler); |
||
| 115 | } else { |
||
| 116 | // Handle the error condition when opendir fails |
||
| 117 | $ret[] = '<span style="color:#ff0000;">ERROR: Could not open the template directory: <b>' . htmlspecialchars($tpl_path, ENT_QUOTES) . '</b>.</span><br>'; |
||
| 118 | } |
||
| 119 | } else { |
||
| 120 | // Directory does not exist; handle this condition |
||
| 121 | $ret[] = '<span style="color:#ff0000;">ERROR: The template directory does not exist or is not readable: <b>' . htmlspecialchars($tpl_path, ENT_QUOTES) . '</b>.</span><br>'; |
||
| 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.