| Conditions | 12 |
| Paths | 96 |
| Total Lines | 88 |
| Code Lines | 63 |
| 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 |
||
| 110 | public static function loadDolibarrConfig(): ?Conf |
||
| 111 | { |
||
| 112 | $filename = self::getDolibarrConfigFilename(); |
||
| 113 | if (file_exists($filename) && is_readable($filename)) { |
||
| 114 | include $filename; |
||
| 115 | } |
||
| 116 | |||
| 117 | /* |
||
| 118 | * Create $conf object |
||
| 119 | */ |
||
| 120 | $conf = new Conf(); |
||
| 121 | |||
| 122 | // Set properties specific to database |
||
| 123 | $conf->db->host = $dolibarr_main_db_host ?? ''; |
||
|
|
|||
| 124 | $conf->db->port = $dolibarr_main_db_port ?? ''; |
||
| 125 | $conf->db->name = $dolibarr_main_db_name ?? ''; |
||
| 126 | $conf->db->user = $dolibarr_main_db_user ?? ''; |
||
| 127 | $conf->db->pass = $dolibarr_main_db_pass ?? ''; |
||
| 128 | $conf->db->type = $dolibarr_main_db_type ?? self::DEFAULT_DB_TYPE; |
||
| 129 | $conf->db->prefix = $dolibarr_main_db_prefix ?? self::DEFAULT_DB_PREFIX; |
||
| 130 | $conf->db->charset = $dolibarr_main_db_character_set ?? self::DEFAULT_CHARSET; |
||
| 131 | $conf->db->collation = $dolibarr_main_db_collation ?? self::DEFAULT_COLLATION; |
||
| 132 | $conf->db->encryption = $dolibarr_main_db_encryption ?? 0; |
||
| 133 | $conf->db->cryptkey = $dolibarr_main_db_cryptkey ?? ''; |
||
| 134 | if (defined('TEST_DB_FORCE_TYPE')) { |
||
| 135 | $conf->db->type = constant('TEST_DB_FORCE_TYPE'); // Force db type (for test purpose, by PHP unit for example) |
||
| 136 | } |
||
| 137 | |||
| 138 | // Set properties specific to conf file |
||
| 139 | $conf->file->main_limit_users = $dolibarr_main_limit_users ?? null; |
||
| 140 | $conf->file->mailing_limit_sendbyweb = $dolibarr_mailing_limit_sendbyweb ?? 0; |
||
| 141 | $conf->file->mailing_limit_sendbycli = $dolibarr_mailing_limit_sendbycli ?? 0; |
||
| 142 | $conf->file->mailing_limit_sendbyday = $dolibarr_mailing_limit_sendbyday ?? 0; |
||
| 143 | $conf->file->main_authentication = $dolibarr_main_authentication ?? self::DEFAULT_AUTHENTICATION_MODE; |
||
| 144 | $conf->file->main_force_https = isset($dolibarr_main_force_https) && $dolibarr_main_force_https ? true : false; |
||
| 145 | $conf->file->strict_mode = $dolibarr_strict_mode ?? ''; |
||
| 146 | $conf->file->instance_unique_id = $dolibarr_main_instance_unique_id ?? ''; |
||
| 147 | $conf->file->main_path = $dolibarr_main_document_root ?? constant('BASE_PATH'); |
||
| 148 | $conf->file->main_url = $dolibarr_main_url_root ?? constant('BASE_URL'); |
||
| 149 | $conf->file->main_doc = $dolibarr_main_data_root ?? static::getDataDir($conf->file->main_path); |
||
| 150 | $conf->file->path = ['main' => $conf->file->main_path]; |
||
| 151 | $conf->file->url = ['main' => '/']; |
||
| 152 | $conf->file->dol_document_root = $conf->file->main_doc; |
||
| 153 | if (!empty($dolibarr_main_document_root_alt)) { |
||
| 154 | $path = preg_split('/[;,]/', $dolibarr_main_document_root_alt); |
||
| 155 | $url = preg_split('/[;,]/', $dolibarr_main_url_root_alt ?? DIRECTORY_SEPARATOR); |
||
| 156 | |||
| 157 | if (count($path) !== count($url)) { |
||
| 158 | print '<b>Error:</b><br>$dolibarr_main_document_root_alt and $dolibarr_main_url_root_alt must contain the same number of elements.<br>'; |
||
| 159 | die(); |
||
| 160 | } |
||
| 161 | |||
| 162 | $i = 0; |
||
| 163 | foreach ($path as $value) { |
||
| 164 | $conf->file->path['alt' . ($i++)] = (string)$value; |
||
| 165 | } |
||
| 166 | $values = preg_split('/[;,]/', $dolibarr_main_url_root_alt); |
||
| 167 | $i = 0; |
||
| 168 | foreach ($url as $value) { |
||
| 169 | if (preg_match('/^http(s)?:/', $value)) { |
||
| 170 | // Show error message |
||
| 171 | $correct_value = str_replace($conf->file->url, '', $value); |
||
| 172 | print '<b>Error:</b><br>' . "\n"; |
||
| 173 | print 'Wrong <b>$dolibarr_main_url_root_alt</b> value in <b>conf.php</b> file.<br>' . "\n"; |
||
| 174 | print 'We now use a relative path to $dolibarr_main_url_root to build alternate URLs.<br>' . "\n"; |
||
| 175 | print 'Value found: ' . $value . '<br>' . "\n"; |
||
| 176 | print 'Should be replaced by: ' . $correct_value . '<br>' . "\n"; |
||
| 177 | print "Or something like following examples:<br>\n"; |
||
| 178 | print "\"/extensions\"<br>\n"; |
||
| 179 | print "\"/extensions1,/extensions2,...\"<br>\n"; |
||
| 180 | print "\"/../extensions\"<br>\n"; |
||
| 181 | print "\"/custom\"<br>\n"; |
||
| 182 | exit; |
||
| 183 | } |
||
| 184 | $conf->file->url['alt' . ($i++)] = (string)$value; |
||
| 185 | } |
||
| 186 | } |
||
| 187 | |||
| 188 | $conf->file->theme = $dolibarr_main_theme ?? self::DEFAULT_THEME; |
||
| 189 | $conf->file->dol_main_stream_to_disable = $dolibarr_main_stream_to_disable ?? null; |
||
| 190 | $conf->debug = intval($dolibarr_main_prod ?? 1) === 0; |
||
| 191 | |||
| 192 | // Load the main includes of common libraries |
||
| 193 | if (!defined('NOREQUIRETRAN')) { |
||
| 194 | require_once BASE_PATH . '/core/class/translate.class.php'; |
||
| 195 | } |
||
| 196 | |||
| 197 | return self::$config = $conf; |
||
| 198 | } |
||
| 253 |