| Conditions | 8 |
| Paths | 7 |
| Total Lines | 64 |
| Code Lines | 32 |
| 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 |
||
| 98 | function executeSQL($sql_file_path) |
||
| 99 | { |
||
| 100 | global $xoopsModule; |
||
| 101 | $error = false; |
||
| 102 | // $reservedTables = array('avatar', 'avatar_users_link', 'block_module_link', 'xoopscomments', 'config', 'configcategory', 'configoption', 'image', 'imagebody', 'imagecategory', 'imgset', 'imgset_tplset_link', 'imgsetimg', 'groups','groups_users_link','group_permission', 'online', 'bannerclient', 'banner', 'bannerfinish', 'ranks', 'session', 'smiles', 'users', 'newblocks', 'modules', 'tplfile', 'tplset', 'tplsource', 'xoopsnotifications', 'banner', 'bannerclient', 'bannerfinish'); |
||
| 103 | // $sql_file_path = XOOPS_ROOT_PATH."/modules/".$xoopsModule->dirname()."/sql/".$sqlfile; |
||
| 104 | if (!file_exists($sql_file_path)) { |
||
| 105 | echo "SQL file not found at <b>$sql_file_path</b><br>"; |
||
| 106 | // $msg = "SQL file not found at <b>$sql_file_path</b><br>"; |
||
| 107 | $error = true; |
||
| 108 | } else { |
||
| 109 | echo "SQL file found at <b>$sql_file_path</b>.<br > Creating tables...<br>"; |
||
| 110 | // $msg = "SQL file found at <b>$sql_file_path</b>.<br > Creating tables...<br>"; |
||
| 111 | require_once XOOPS_ROOT_PATH . '/class/database/sqlutility.php'; |
||
| 112 | $sql_query = fread(fopen($sql_file_path, 'rb'), filesize($sql_file_path)); |
||
| 113 | $sql_query = trim($sql_query); |
||
| 114 | SqlUtility::splitMySqlFile($pieces, $sql_query); |
||
| 115 | $created_tables = []; |
||
| 116 | foreach ($pieces as $piece) { |
||
| 117 | // [0] contains the prefixed query |
||
| 118 | // [4] contains unprefixed table name |
||
| 119 | $prefixed_query = SqlUtility::prefixQuery($piece, $GLOBALS['xoopsDB']->prefix()); |
||
| 120 | if (!$prefixed_query) { |
||
| 121 | // $msg = "<b>$piece</b> is not a valid SQL!<br>"; |
||
| 122 | echo "<b>$piece</b> is not a valid SQL!<br>"; |
||
| 123 | $error = true; |
||
| 124 | break; |
||
| 125 | } |
||
| 126 | // check if the table name is reserved |
||
| 127 | //if (!in_array($prefixed_query[4], $reservedTables)) { |
||
| 128 | // not reserved, so try to create one |
||
| 129 | if (!$GLOBALS['xoopsDB']->query($prefixed_query[0])) { |
||
| 130 | //$this->setErrors($GLOBALS['xoopsDB']->error()); |
||
| 131 | echo 'erreur<br>'; |
||
| 132 | $error = true; |
||
| 133 | break; |
||
| 134 | } else { |
||
| 135 | if (!in_array($prefixed_query[4], $created_tables)) { |
||
| 136 | // $msg = ' Table <b>'.$GLOBALS['xoopsDB']->prefix($prefixed_query[4]).'</b> created.<br>'; |
||
| 137 | echo ' Table <b>' . $GLOBALS['xoopsDB']->prefix($prefixed_query[4]) . '</b> created.<br>'; |
||
| 138 | $created_tables[] = $prefixed_query[4]; |
||
| 139 | } else { |
||
| 140 | echo ' Data inserted to table <b>' . $GLOBALS['xoopsDB']->prefix($prefixed_query[4]) . '</b>.<br>'; |
||
| 141 | // $msg = ' Data inserted to table <b>'.$GLOBALS['xoopsDB']->prefix($prefixed_query[4]).'</b>.<br>'; |
||
| 142 | } |
||
| 143 | } |
||
| 144 | // } else { |
||
| 145 | // the table name is reserved, so halt the installation |
||
| 146 | // $this->setErrors('<b>'.$prefixed_query[4]."</b> is a reserved table!"); |
||
| 147 | // $error = true; |
||
| 148 | // break; |
||
| 149 | // } |
||
| 150 | } |
||
| 151 | // if there was an error, delete the tables created so far, so the next installation will not fail |
||
| 152 | if (true === $error) { |
||
| 153 | foreach ($created_tables as $ct) { |
||
| 154 | //echo $ct; |
||
| 155 | $GLOBALS['xoopsDB']->query('DROP TABLE ' . $GLOBALS['xoopsDB']->prefix($ct)); |
||
| 156 | } |
||
| 157 | } |
||
| 158 | } |
||
| 159 | |||
| 160 | //} |
||
| 161 | return $error; |
||
| 162 | } |
||
| 163 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.