| Conditions | 8 |
| Paths | 7 |
| Total Lines | 65 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | 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 |
||
| 93 | function executeSQL($sql_file_path) |
||
| 94 | { |
||
| 95 | global $xoopsModule; |
||
| 96 | $error = false; |
||
| 97 | // $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'); |
||
| 98 | // $sql_file_path = XOOPS_ROOT_PATH."/modules/".$xoopsModule->dirname()."/sql/".$sqlfile; |
||
| 99 | if (!file_exists($sql_file_path)) { |
||
| 100 | echo "SQL file not found at <b>$sql_file_path</b><br>"; |
||
| 101 | // $msg = "SQL file not found at <b>$sql_file_path</b><br>"; |
||
| 102 | $error = true; |
||
| 103 | } else { |
||
| 104 | echo "SQL file found at <b>$sql_file_path</b>.<br /> Creating tables...<br>"; |
||
| 105 | // $msg = "SQL file found at <b>$sql_file_path</b>.<br /> Creating tables...<br>"; |
||
| 106 | include_once XOOPS_ROOT_PATH . '/class/database/sqlutility.php'; |
||
| 107 | $sql_query = fread(fopen($sql_file_path, 'r'), filesize($sql_file_path)); |
||
| 108 | $sql_query = trim($sql_query); |
||
| 109 | SqlUtility::splitMySqlFile($pieces, $sql_query); |
||
| 110 | $created_tables = array(); |
||
| 111 | foreach ($pieces as $piece) { |
||
| 112 | // [0] contains the prefixed query |
||
| 113 | // [4] contains unprefixed table name |
||
| 114 | $prefixed_query = SqlUtility::prefixQuery($piece, $GLOBALS['xoopsDB']->prefix()); |
||
| 115 | if (!$prefixed_query) { |
||
| 116 | // $msg = "<b>$piece</b> is not a valid SQL!<br>"; |
||
| 117 | echo "<b>$piece</b> is not a valid SQL!<br>"; |
||
| 118 | $error = true; |
||
| 119 | break; |
||
| 120 | } |
||
| 121 | // check if the table name is reserved |
||
| 122 | //if (!in_array($prefixed_query[4], $reservedTables)) { |
||
| 123 | // not reserved, so try to create one |
||
| 124 | if (!$GLOBALS['xoopsDB']->query($prefixed_query[0])) { |
||
| 125 | //$this->setErrors($GLOBALS['xoopsDB']->error()); |
||
| 126 | echo 'erreur<br>'; |
||
| 127 | $error = true; |
||
| 128 | break; |
||
| 129 | } else { |
||
| 130 | if (!in_array($prefixed_query[4], $created_tables)) { |
||
| 131 | // $msg = ' Table <b>'.$GLOBALS['xoopsDB']->prefix($prefixed_query[4]).'</b> created.<br>'; |
||
| 132 | echo ' Table <b>' . $GLOBALS['xoopsDB']->prefix($prefixed_query[4]) . '</b> created.<br>'; |
||
| 133 | $created_tables[] = $prefixed_query[4]; |
||
| 134 | } else { |
||
| 135 | echo ' Data inserted to table <b>' . $GLOBALS['xoopsDB']->prefix($prefixed_query[4]) . '</b>.<br>'; |
||
| 136 | // $msg = ' Data inserted to table <b>'.$GLOBALS['xoopsDB']->prefix($prefixed_query[4]).'</b>.<br>'; |
||
| 137 | } |
||
| 138 | } |
||
| 139 | // } else { |
||
| 140 | // the table name is reserved, so halt the installation |
||
| 141 | // $this->setErrors('<b>'.$prefixed_query[4]."</b> is a reserved table!"); |
||
| 142 | // $error = true; |
||
| 143 | // break; |
||
| 144 | // } |
||
| 145 | } |
||
| 146 | // if there was an error, delete the tables created so far, so the next installation will not fail |
||
| 147 | if ($error === true) { |
||
| 148 | foreach ($created_tables as $ct) { |
||
| 149 | //echo $ct; |
||
| 150 | $GLOBALS['xoopsDB']->query('DROP TABLE ' . $GLOBALS['xoopsDB']->prefix($ct)); |
||
| 151 | } |
||
| 152 | } |
||
| 153 | } |
||
| 154 | |||
| 155 | //} |
||
| 156 | return $error; |
||
| 157 | } |
||
| 158 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.