Conditions | 9 |
Paths | 13 |
Total Lines | 56 |
Code Lines | 41 |
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 |
||
72 | function get_installmode() |
||
73 | { |
||
74 | global $base_path, $database_server, $database_user, $database_password, $dbase, $table_prefix; |
||
75 | |||
76 | $conf_path = "{$base_path}manager/includes/config.inc.php"; |
||
77 | if (!is_file($conf_path)) { |
||
78 | $installmode = 0; |
||
79 | } elseif (isset($_POST['installmode'])) { |
||
80 | $installmode = $_POST['installmode']; |
||
81 | } else { |
||
82 | include_once("{$base_path}manager/includes/config.inc.php"); |
||
83 | |||
84 | if (!isset($dbase) || empty($dbase)) { |
||
85 | $installmode = 0; |
||
86 | } else { |
||
87 | $conn = mysqli_connect($database_server, $database_user, $database_password); |
||
88 | if ($conn) { |
||
89 | $_SESSION['database_server'] = $database_server; |
||
90 | $_SESSION['database_user'] = $database_user; |
||
91 | $_SESSION['database_password'] = $database_password; |
||
92 | |||
93 | $dbase = trim($dbase, '`'); |
||
94 | $rs = mysqli_select_db($conn, $dbase); |
||
95 | } else { |
||
96 | $rs = false; |
||
97 | } |
||
98 | |||
99 | if ($rs) { |
||
100 | $_SESSION['dbase'] = $dbase; |
||
101 | $_SESSION['table_prefix'] = $table_prefix; |
||
102 | $_SESSION['database_collation'] = 'utf8_general_ci'; |
||
103 | $_SESSION['database_connection_method'] = 'SET CHARACTER SET'; |
||
104 | |||
105 | $tbl_system_settings = "`{$dbase}`.`{$table_prefix}system_settings`"; |
||
106 | $rs = mysqli_query($conn, |
||
107 | "SELECT setting_value FROM {$tbl_system_settings} WHERE setting_name='settings_version'"); |
||
108 | if ($rs) { |
||
109 | $row = mysqli_fetch_assoc($rs); |
||
110 | $settings_version = $row['setting_value']; |
||
111 | } else { |
||
112 | $settings_version = ''; |
||
113 | } |
||
114 | |||
115 | if (empty($settings_version)) { |
||
116 | $installmode = 0; |
||
117 | } else { |
||
118 | $installmode = 1; |
||
119 | } |
||
120 | } else { |
||
121 | $installmode = 1; |
||
122 | } |
||
123 | } |
||
124 | } |
||
125 | |||
126 | return $installmode; |
||
127 | } |
||
128 | } |
||
165 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.