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