| Conditions | 18 |
| Paths | 320 |
| Total Lines | 69 |
| Code Lines | 42 |
| 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 |
||
| 7 | function apphp_db_install($sql_dump_file) { |
||
| 8 | global $error_mg; |
||
| 9 | global $admin_username; |
||
| 10 | global $admin_password; |
||
| 11 | global $database_prefix; |
||
| 12 | global $password_encryption; |
||
| 13 | global $db; |
||
| 14 | |||
| 15 | $sql_array = array(); |
||
| 16 | $query = ''; |
||
| 17 | |||
| 18 | // get sql dump content |
||
| 19 | $sql_dump = file($sql_dump_file); |
||
| 20 | |||
| 21 | // replace database prefix if exists |
||
| 22 | $sql_dump = str_ireplace('<DB_PREFIX>', $database_prefix, $sql_dump); |
||
| 23 | |||
| 24 | // disabling magic quotes at runtime |
||
| 25 | if(get_magic_quotes_runtime()){ |
||
| 26 | function stripslashes_runtime(&$value){ |
||
| 27 | $value = stripslashes($value); |
||
| 28 | } |
||
| 29 | array_walk_recursive($sql_dump, 'stripslashes_runtime'); |
||
| 30 | } |
||
| 31 | |||
| 32 | // add ';' at the end of file to catch last sql query |
||
| 33 | if(substr($sql_dump[count($sql_dump)-1], -1) != ';') $sql_dump[count($sql_dump)-1] .= ';'; |
||
| 34 | |||
| 35 | // replace username and password if exists |
||
| 36 | if(EI_USE_ADMIN_ACCOUNT){ |
||
| 37 | $sql_dump = str_ireplace('<USER_NAME>', $admin_username, $sql_dump); |
||
| 38 | if(EI_USE_PASSWORD_ENCRYPTION){ |
||
| 39 | if($password_encryption == 'AES'){ |
||
| 40 | $sql_dump = str_ireplace('<PASSWORD>', 'AES_ENCRYPT(\''.$admin_password.'\', \''.EI_PASSWORD_ENCRYPTION_KEY.'\')', $sql_dump); |
||
| 41 | }else if($password_encryption == 'MD5'){ |
||
| 42 | $sql_dump = str_ireplace('<PASSWORD>', 'MD5(\''.$admin_password.'\')', $sql_dump); |
||
| 43 | }else{ |
||
| 44 | $sql_dump = str_ireplace('<PASSWORD>', 'AES_ENCRYPT(\''.$admin_password.'\', \''.EI_PASSWORD_ENCRYPTION_KEY.'\')', $sql_dump); |
||
| 45 | } |
||
| 46 | }else{ |
||
| 47 | $sql_dump = str_ireplace('<PASSWORD>', '\''.$admin_password.'\'', $sql_dump); |
||
| 48 | } |
||
| 49 | }else{ |
||
| 50 | $sql_dump = str_ireplace('<USER_NAME>', '', $sql_dump); |
||
| 51 | $sql_dump = str_ireplace('<PASSWORD>', "''", $sql_dump); |
||
| 52 | } |
||
| 53 | |||
| 54 | // encode connection, server, client etc. |
||
| 55 | if(EI_USE_ENCODING){ |
||
| 56 | $db->SetEncoding(EI_DUMP_FILE_ENCODING, EI_DUMP_FILE_COLLATION); |
||
| 57 | } |
||
| 58 | |||
| 59 | foreach($sql_dump as $sql_line){ |
||
| 60 | $tsl = trim(utf8_decode($sql_line)); |
||
| 61 | if(($sql_line != '') && (substr($tsl, 0, 2) != '--') && (substr($tsl, 0, 1) != '?') && (substr($tsl, 0, 1) != '#')){ |
||
| 62 | $query .= $sql_line; |
||
| 63 | if(preg_match("/;\s*$/", $sql_line)){ |
||
| 64 | if(strlen(trim($query)) > 5){ |
||
| 65 | if(EI_MODE == 'debug'){ |
||
| 66 | if(!$db->Query($query)){ $error_mg[] = '<b>SQL</b>:'.$query.'<br /><br /><b>'.lang_key('error').'</b>:<br />'.$db->Error(); return false; } |
||
| 67 | }else{ |
||
| 68 | if(!@$db->Query($query)) return false; |
||
| 69 | } |
||
| 70 | } |
||
| 71 | $query = ''; |
||
| 72 | } |
||
| 73 | } |
||
| 74 | } |
||
| 75 | return true; |
||
| 76 | } |
||
| 171 |