Conditions | 26 |
Paths | > 20000 |
Total Lines | 87 |
Code Lines | 60 |
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 |
||
163 | public static function loadConf($reload = false): ?stdClass |
||
164 | { |
||
165 | if (isset(static::$conf) && !$reload) { |
||
166 | return static::$conf; |
||
167 | } |
||
168 | |||
169 | $filename = static::getDolibarrConfigFilename(); |
||
170 | $exists = file_exists($filename) && is_readable($filename); |
||
171 | if ($exists) { |
||
172 | include $filename; |
||
173 | } |
||
174 | |||
175 | /* |
||
176 | * Create $conf object |
||
177 | */ |
||
178 | |||
179 | $conf = new Conf(); |
||
180 | |||
181 | // Set properties specific to database |
||
182 | $conf->db->host = empty($dolibarr_main_db_host) ? '' : $dolibarr_main_db_host; |
||
183 | $conf->db->port = empty($dolibarr_main_db_port) ? '' : $dolibarr_main_db_port; |
||
184 | $conf->db->name = empty($dolibarr_main_db_name) ? '' : $dolibarr_main_db_name; |
||
185 | $conf->db->user = empty($dolibarr_main_db_user) ? '' : $dolibarr_main_db_user; |
||
186 | $conf->db->pass = empty($dolibarr_main_db_pass) ? '' : $dolibarr_main_db_pass; |
||
187 | $conf->db->type = $dolibarr_main_db_type ?? 'mysqli'; |
||
188 | $conf->db->prefix = $dolibarr_main_db_prefix ?? 'alx_'; |
||
189 | $conf->db->character_set = $dolibarr_main_db_character_set ?? 'utf8'; |
||
190 | $conf->db->dolibarr_main_db_collation = $dolibarr_main_db_collation ?? 'utf8-unicode-ci'; |
||
191 | $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption ?? null; |
||
192 | $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey ?? null; |
||
193 | if (defined('TEST_DB_FORCE_TYPE')) { |
||
194 | $conf->db->type = constant('TEST_DB_FORCE_TYPE'); // Force db type (for test purpose, by PHP unit for example) |
||
195 | } |
||
196 | |||
197 | // Set properties specific to conf file |
||
198 | $conf->file->main_limit_users = $dolibarr_main_limit_users ?? null; |
||
199 | $conf->file->mailing_limit_sendbyweb = empty($dolibarr_mailing_limit_sendbyweb) ? 0 : $dolibarr_mailing_limit_sendbyweb; |
||
200 | $conf->file->mailing_limit_sendbycli = empty($dolibarr_mailing_limit_sendbycli) ? 0 : $dolibarr_mailing_limit_sendbycli; |
||
201 | $conf->file->mailing_limit_sendbyday = empty($dolibarr_mailing_limit_sendbyday) ? 0 : $dolibarr_mailing_limit_sendbyday; |
||
202 | $conf->file->main_authentication = empty($dolibarr_main_authentication) ? 'dolibarr' : $dolibarr_main_authentication; // Identification mode |
||
203 | $conf->file->main_force_https = empty($dolibarr_main_force_https) ? '' : $dolibarr_main_force_https; // Force https |
||
204 | $conf->file->strict_mode = empty($dolibarr_strict_mode) ? '' : $dolibarr_strict_mode; // Force php strict mode (for debug) |
||
205 | $conf->file->instance_unique_id = empty($dolibarr_main_instance_unique_id) ? (empty($dolibarr_main_cookie_cryptkey) ? '' : $dolibarr_main_cookie_cryptkey) : $dolibarr_main_instance_unique_id; // Unique id of instance |
||
206 | $conf->file->dol_main_url_root = $dolibarr_main_url_root ?? BASE_URL; // Define url inside the config file |
||
207 | $conf->file->dol_document_root = ['main' => (string) DOL_DOCUMENT_ROOT]; // Define array of document root directories ('/home/htdocs') |
||
208 | $conf->file->dol_url_root = ['main' => (string) DOL_URL_ROOT]; // Define array of url root path ('' or '/dolibarr') |
||
209 | if (!empty($dolibarr_main_document_root_alt)) { |
||
210 | // dolibarr_main_document_root_alt can contains several directories |
||
211 | $values = preg_split('/[;,]/', $dolibarr_main_document_root_alt); |
||
212 | $i = 0; |
||
213 | foreach ($values as $value) { |
||
214 | $conf->file->dol_document_root['alt' . ($i++)] = (string) $value; |
||
215 | } |
||
216 | $values = preg_split('/[;,]/', $dolibarr_main_url_root_alt); |
||
217 | $i = 0; |
||
218 | foreach ($values as $value) { |
||
219 | if (preg_match('/^http(s)?:/', $value)) { |
||
220 | // Show error message |
||
221 | $correct_value = str_replace($dolibarr_main_url_root, '', $value); |
||
222 | print '<b>Error:</b><br>' . "\n"; |
||
223 | print 'Wrong <b>$dolibarr_main_url_root_alt</b> value in <b>conf.php</b> file.<br>' . "\n"; |
||
224 | print 'We now use a relative path to $dolibarr_main_url_root to build alternate URLs.<br>' . "\n"; |
||
225 | print 'Value found: ' . $value . '<br>' . "\n"; |
||
226 | print 'Should be replaced by: ' . $correct_value . '<br>' . "\n"; |
||
227 | print "Or something like following examples:<br>\n"; |
||
228 | print "\"/extensions\"<br>\n"; |
||
229 | print "\"/extensions1,/extensions2,...\"<br>\n"; |
||
230 | print "\"/../extensions\"<br>\n"; |
||
231 | print "\"/custom\"<br>\n"; |
||
232 | exit; |
||
233 | } |
||
234 | $conf->file->dol_url_root['alt' . ($i++)] = (string) $value; |
||
235 | } |
||
236 | } |
||
237 | |||
238 | // Load the main includes of common libraries |
||
239 | if (!defined('NOREQUIREUSER')) { |
||
240 | require_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php'; // Need 500ko memory |
||
241 | } |
||
242 | if (!defined('NOREQUIRETRAN')) { |
||
243 | require_once DOL_DOCUMENT_ROOT . '/core/class/translate.class.php'; |
||
244 | } |
||
245 | if (!defined('NOREQUIRESOC')) { |
||
246 | require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php'; |
||
247 | } |
||
248 | |||
249 | return $conf; |
||
250 | } |
||
300 |