Conditions | 12 |
Paths | 960 |
Total Lines | 99 |
Code Lines | 60 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 1 | 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 | public function actionInstall() |
||
120 | { |
||
121 | $config = App::$Properties->get('database'); |
||
122 | $newConfig = []; |
||
123 | // creating default directory's |
||
124 | foreach ($this->installDirs as $obj) { |
||
125 | // looks like a directory |
||
126 | if (!Str::contains('.', $obj)) { |
||
127 | Directory::create($obj, 0777); |
||
128 | } |
||
129 | } |
||
130 | echo App::$Output->write('Upload and private directories are successful created!'); |
||
131 | |||
132 | // set chmods |
||
133 | echo $this->actionChmod(); |
||
134 | |||
135 | // database config from input |
||
136 | echo App::$Output->writeHeader('Database connection configuration'); |
||
137 | echo 'Driver(default:' . $config['driver'] . '):'; |
||
138 | $dbDriver = App::$Input->read(); |
||
139 | if (Arr::in($dbDriver, ['mysql', 'pgsql', 'sqlite'])) { |
||
140 | $newConfig['driver'] = $dbDriver; |
||
141 | } |
||
142 | |||
143 | // for sqlite its would be a path |
||
144 | echo 'Host(default:' . $config['host'] . '):'; |
||
145 | $dbHost = App::$Input->read(); |
||
146 | if (!Str::likeEmpty($dbHost)) { |
||
147 | $newConfig['host'] = $dbHost; |
||
148 | } |
||
149 | |||
150 | echo 'Database name(default:' . $config['database'] . '):'; |
||
151 | $dbName = App::$Input->read(); |
||
152 | if (!Str::likeEmpty($dbName)) { |
||
153 | $newConfig['database'] = $dbName; |
||
154 | } |
||
155 | |||
156 | echo 'User(default:' . $config['username'] . '):'; |
||
157 | $dbUser = App::$Input->read(); |
||
158 | if (!Str::likeEmpty($dbUser)) { |
||
159 | $newConfig['username'] = $dbUser; |
||
160 | } |
||
161 | |||
162 | echo 'Password(default:' . $config['password'] . '):'; |
||
163 | $dbPwd = App::$Input->read(); |
||
164 | if (!Str::likeEmpty($dbPwd)) { |
||
165 | $newConfig['password'] = $dbPwd; |
||
166 | } |
||
167 | |||
168 | echo 'Table prefix(default:' . $config['prefix'] . '):'; |
||
169 | $dbPrefix = App::$Input->read(); |
||
170 | if (!Str::likeEmpty($dbPrefix)) { |
||
171 | $newConfig['prefix'] = $dbPrefix; |
||
172 | } |
||
173 | |||
174 | // merge configs and add new connection to db pull |
||
175 | $dbConfigs = Arr::merge($config, $newConfig); |
||
176 | App::$Database->addConnection($dbConfigs, 'install'); |
||
177 | |||
178 | try { |
||
179 | App::$Database->connection('install')->getDatabaseName(); |
||
180 | } catch (\Exception $e) { |
||
181 | return 'Testing database connection is failed! Run installer again and pass tested connection data! Log: ' . $e->getMessage(); |
||
182 | } |
||
183 | |||
184 | // autoload isn't work here |
||
185 | include(root . '/Apps/Controller/Console/Db.php'); |
||
186 | |||
187 | // import db data |
||
188 | $dbController = new DbController(); |
||
189 | echo $dbController->actionImportAll('install'); |
||
190 | |||
191 | // set website send from email from input |
||
192 | $emailConfig = App::$Properties->get('adminEmail'); |
||
193 | echo 'Website sendFrom email(default: ' . $emailConfig . '):'; |
||
194 | $email = App::$Input->read(); |
||
195 | if (!Str::isEmail($email)) { |
||
196 | $email = $emailConfig; |
||
197 | } |
||
198 | |||
199 | // generate other configuration data and security salt, key's and other |
||
200 | echo App::$Output->writeHeader('Writing configurations'); |
||
201 | $allCfg = App::$Properties->getAll('default'); |
||
202 | $allCfg['database'] = $dbConfigs; |
||
203 | $allCfg['adminEmail'] = $email; |
||
204 | echo App::$Output->write('Generate password salt for BLOWFISH crypt'); |
||
205 | $allCfg['passwordSalt'] = Str::randomLatinNumeric(mt_rand(21, 30)) . '$'; |
||
206 | echo App::$Output->write('Generate security cookies for debug panel'); |
||
207 | $allCfg['debug']['cookie']['key'] = 'fdebug_' . Str::randomLatinNumeric(mt_rand(8, 32)); |
||
208 | $allCfg['debug']['cookie']['value'] = Str::randomLatinNumeric(mt_rand(32, 128)); |
||
209 | |||
210 | // write config data |
||
211 | $writeCfg = App::$Properties->writeConfig('default', $allCfg); |
||
212 | if ($writeCfg !== true) { |
||
213 | return 'File /Private/Config/Default.php is unavailable to write data!'; |
||
214 | } |
||
215 | |||
216 | return 'Configuration done! FFCMS 3 is successful installed! Visit your website. You can add administrator using command php console.php db/adduser'; |
||
217 | } |
||
218 | } |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.