| Conditions | 13 |
| Paths | 153 |
| Total Lines | 81 |
| Code Lines | 57 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 119 | function install_process ($argv = null) { |
||
| 120 | if (isset($_POST['site_url'])) { |
||
| 121 | $url = $_POST['site_url']; |
||
| 122 | } else { |
||
| 123 | $https = @$_SERVER['HTTPS'] ? $_SERVER['HTTPS'] !== 'off' : ( |
||
| 124 | @$_SERVER['REQUEST_SCHEME'] === 'https' || |
||
| 125 | @$_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https' |
||
| 126 | ); |
||
| 127 | $scheme = $https ? 'https' : 'http'; |
||
| 128 | $host = explode(':', $_SERVER['HTTP_HOST'])[0]; |
||
| 129 | $path = explode('?', $_SERVER['REQUEST_URI'])[0] ?: '/'; |
||
| 130 | $url = "$scheme://$host$path"; |
||
| 131 | $url = implode('/', array_slice(explode('/', $url), 0, -2)); //Remove 2 last items |
||
| 132 | } |
||
| 133 | try { |
||
| 134 | Installer::install( |
||
| 135 | DIR, |
||
| 136 | ROOT, |
||
| 137 | $_POST['site_name'], |
||
| 138 | $url, |
||
| 139 | $_POST['timezone'], |
||
| 140 | $_POST['db_host'], |
||
| 141 | $_POST['db_engine'], |
||
| 142 | $_POST['db_name'], |
||
| 143 | $_POST['db_user'], |
||
| 144 | $_POST['db_password'], |
||
| 145 | $_POST['db_prefix'], |
||
| 146 | $_POST['db_charset'], |
||
| 147 | $_POST['language'], |
||
| 148 | $_POST['admin_email'], |
||
| 149 | $_POST['admin_password'], |
||
| 150 | !isset($_POST['mode']) || $_POST['mode'] ? 1 : 0 |
||
| 151 | ); |
||
| 152 | } catch (\Exception $e) { |
||
| 153 | return $e; |
||
| 154 | } |
||
| 155 | $admin_login = strstr($_POST['admin_email'], '@', true); |
||
| 156 | $warning = false; |
||
| 157 | // Removing of installer file |
||
| 158 | $cli = PHP_SAPI == 'cli'; |
||
| 159 | $installer = $cli ? ROOT."/$argv[0]" : ROOT.'/'.pathinfo(DIR, PATHINFO_BASENAME); |
||
| 160 | if (!is_writable($installer) || !unlink($installer)) { |
||
| 161 | $warning = "Please, remove installer file $installer for security!\n"; |
||
| 162 | } |
||
| 163 | if ($cli) { |
||
| 164 | return "Congratulations! CleverStyle CMS has been installed successfully!\n$warning\nLogin: $admin_login\nPassword: $_POST[admin_password]"; |
||
| 165 | } else { |
||
| 166 | return |
||
| 167 | h::h3( |
||
| 168 | 'Congratulations! CleverStyle CMS has been installed successfully!' |
||
| 169 | ). |
||
| 170 | h::{'table tr| td'}( |
||
| 171 | [ |
||
| 172 | 'Your sign in information:', |
||
| 173 | [ |
||
| 174 | 'colspan' => 2 |
||
| 175 | ] |
||
| 176 | ], |
||
| 177 | [ |
||
| 178 | 'Login:', |
||
| 179 | $admin_login |
||
| 180 | ], |
||
| 181 | [ |
||
| 182 | 'Password:', |
||
| 183 | $_POST['admin_password'] |
||
| 184 | ] |
||
| 185 | ). |
||
| 186 | h::p( |
||
| 187 | $warning, |
||
| 188 | [ |
||
| 189 | 'style' => 'color: red;' |
||
| 190 | ] |
||
| 191 | ). |
||
| 192 | h::button( |
||
| 193 | 'Go to website', |
||
| 194 | [ |
||
| 195 | 'onclick' => "location.href = '/';" |
||
| 196 | ] |
||
| 197 | ); |
||
| 198 | } |
||
| 199 | } |
||
| 200 |