| Conditions | 16 |
| Paths | 32 |
| Total Lines | 108 |
| Code Lines | 72 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 | $db = XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 35 | $mid = $module->getVar('mid'); |
||
| 36 | if (!is_array($ret)) { |
||
| 37 | $ret = array(); |
||
| 38 | } |
||
| 39 | |||
| 40 | // TABLES (loading mysql.sql) |
||
| 41 | $sql_file_path = __DIR__ . '/sql/mysql.sql'; |
||
| 42 | $prefix_mod = $db->prefix() . '_' . $mydirname; |
||
| 43 | if (file_exists($sql_file_path)) { |
||
| 44 | $ret[] = 'SQL file found at <b>' . htmlspecialchars($sql_file_path, ENT_QUOTES) . '</b>.<br> Creating tables...'; |
||
| 45 | |||
| 46 | include_once XOOPS_ROOT_PATH . '/class/database/sqlutility.php'; |
||
| 47 | $sqlutil = new SqlUtility; //old code is -> $sqlutil =& new SqlUtility ; //hack by Trabis |
||
| 48 | |||
| 49 | $sql_query = trim(file_get_contents($sql_file_path)); |
||
| 50 | $sqlutil->splitMySqlFile($pieces, $sql_query); |
||
| 51 | $created_tables = array(); |
||
| 52 | foreach ($pieces as $piece) { |
||
| 53 | $prefixed_query = $sqlutil->prefixQuery($piece, $prefix_mod); |
||
| 54 | if (!$prefixed_query) { |
||
| 55 | $ret[] = 'Invalid SQL <b>' . htmlspecialchars($piece, ENT_QUOTES) . '</b><br>'; |
||
| 56 | |||
| 57 | return false; |
||
| 58 | } |
||
| 59 | if (!$db->query($prefixed_query[0])) { |
||
| 60 | $ret[] = '<b>' . htmlspecialchars($db->error(), ENT_QUOTES) . '</b><br>'; |
||
| 61 | |||
| 62 | //var_dump( $db->error() ) ; |
||
| 63 | return false; |
||
| 64 | } else { |
||
| 65 | if (!in_array($prefixed_query[4], $created_tables)) { |
||
| 66 | $ret[] = 'Table <b>' . htmlspecialchars($prefix_mod . '_' . $prefixed_query[4], ENT_QUOTES) . '</b> created.<br>'; |
||
| 67 | $created_tables[] = $prefixed_query[4]; |
||
| 68 | } else { |
||
| 69 | $ret[] = 'Data inserted to table <b>' . htmlspecialchars($prefix_mod . '_' . $prefixed_query[4], ENT_QUOTES) . '</b>.</br />'; |
||
| 70 | } |
||
| 71 | } |
||
| 72 | } |
||
| 73 | } |
||
| 74 | |||
| 75 | // TEMPLATES |
||
| 76 | $tplfile_handler = xoops_getHandler('tplfile'); |
||
| 77 | $tpl_path = __DIR__ . '/templates'; |
||
| 78 | // Check if the directory exists |
||
| 79 | if (is_dir($tpl_path)) { |
||
| 80 | // Try to open the directory |
||
| 81 | $handler = opendir($tpl_path . '/'); |
||
| 82 | if (false !== $handler) { |
||
| 83 | while (($file = readdir($handler)) !== false) { |
||
| 84 | if (substr($file, 0, 1) === '.') { |
||
| 85 | continue; |
||
| 86 | } |
||
| 87 | $file_path = $tpl_path . '/' . $file; |
||
| 88 | if (is_file($file_path) && in_array(strrchr($file, '.'), array('.html', '.css', '.js'))) { |
||
| 89 | $mtime = (int)(@filemtime($file_path)); |
||
| 90 | $tplfile = $tplfile_handler->create(); |
||
| 91 | $tplfile->setVar('tpl_source', file_get_contents($file_path), true); |
||
| 92 | $tplfile->setVar('tpl_refid', $mid); |
||
| 93 | $tplfile->setVar('tpl_tplset', 'default'); |
||
| 94 | $tplfile->setVar('tpl_file', $mydirname . '_' . $file); |
||
| 95 | $tplfile->setVar('tpl_desc', '', true); |
||
| 96 | $tplfile->setVar('tpl_module', $mydirname); |
||
| 97 | $tplfile->setVar('tpl_lastmodified', $mtime); |
||
| 98 | $tplfile->setVar('tpl_lastimported', 0); |
||
| 99 | $tplfile->setVar('tpl_type', 'module'); |
||
| 100 | if (!$tplfile_handler->insert($tplfile)) { |
||
| 101 | $ret[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>' . htmlspecialchars($mydirname . '_' . $file, ENT_QUOTES) . '</b> to the database.</span><br>'; |
||
| 102 | } else { |
||
| 103 | $tplid = $tplfile->getVar('tpl_id'); |
||
| 104 | $ret[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file, ENT_QUOTES) . '</b> added to the database. (ID: <b>' . $tplid . '</b>)<br>'; |
||
| 105 | // generate compiled file |
||
| 106 | include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php'; |
||
| 107 | include_once XOOPS_ROOT_PATH . '/class/template.php'; |
||
| 108 | if (!xoops_template_touch($tplid)) { |
||
| 109 | $ret[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>' . htmlspecialchars($mydirname . '_' . $file, ENT_QUOTES) . '</b>.</span><br>'; |
||
| 110 | } else { |
||
| 111 | $ret[] = 'Template <b>' . htmlspecialchars($mydirname . '_' . $file, ENT_QUOTES) . '</b> compiled.</span><br>'; |
||
| 112 | } |
||
| 113 | } |
||
| 114 | } |
||
| 115 | } |
||
| 116 | closedir($handler); |
||
| 117 | } else { |
||
| 118 | // Handle the error condition when opendir fails |
||
| 119 | $ret[] = '<span style="color:#ff0000;">ERROR: Could not open the directory: <b>' . htmlspecialchars($tpl_path) . '</b>.</span><br>'; |
||
| 120 | } |
||
| 121 | closedir($handler); |
||
| 122 | } else { |
||
| 123 | // Directory does not exist; handle this condition |
||
| 124 | $ret[] = '<span style="color:#ff0000;">ERROR: Directory does not exist: <b>' . htmlspecialchars($tpl_path) . '</b>.</span><br>'; |
||
| 125 | } |
||
| 126 | include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php'; |
||
| 127 | include_once XOOPS_ROOT_PATH . '/class/template.php'; |
||
| 128 | xoops_template_clear_module_cache($mid); |
||
| 129 | |||
| 130 | return true; |
||
| 131 | } |
||
| 148 |
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.