Conditions | 24 |
Paths | 4116 |
Total Lines | 118 |
Code Lines | 53 |
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 |
||
171 | public function load_arrays($user, $filter = '') |
||
172 | { |
||
173 | // phpcs:enable |
||
174 | global $langs, $conf; |
||
175 | |||
176 | dol_syslog(get_class($this) . "::load_arrays user=" . $user->id . " filter=" . $filter); |
||
177 | |||
178 | $i = 0; |
||
179 | |||
180 | require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/functions2.lib.php'; |
||
181 | $modulesdir = dolGetModulesDirs(); |
||
182 | |||
183 | // Load list of modules |
||
184 | foreach ($modulesdir as $dir) { |
||
185 | $handle = @opendir(dol_osencode($dir)); |
||
186 | if (!is_resource($handle)) { |
||
187 | continue; |
||
188 | } |
||
189 | |||
190 | // Search module files |
||
191 | while (($file = readdir($handle)) !== false) { |
||
192 | if (!preg_match("/^(mod.*)\.class\.php/i", $file, $reg)) { |
||
193 | continue; |
||
194 | } |
||
195 | |||
196 | $modulename = $reg[1]; |
||
197 | |||
198 | // Defined if module is enabled |
||
199 | $enabled = true; |
||
200 | $part = strtolower(preg_replace('/^mod/i', '', $modulename)); |
||
201 | // Adds condition for propal module |
||
202 | if ($part === 'propale') { |
||
203 | $part = 'propal'; |
||
204 | } |
||
205 | if (empty($conf->$part->enabled)) { |
||
206 | $enabled = false; |
||
207 | } |
||
208 | |||
209 | if (empty($enabled)) { |
||
210 | continue; |
||
211 | } |
||
212 | |||
213 | // Init load class |
||
214 | $file = $dir . "/" . $modulename . ".class.php"; |
||
215 | $classname = $modulename; |
||
216 | require_once $file; |
||
217 | $module = new $classname($this->db); |
||
218 | |||
219 | if (isset($module->import_code) && is_array($module->import_code)) { |
||
220 | foreach ($module->import_code as $r => $value) { |
||
221 | if ($filter && ($filter != $module->import_code[$r])) { |
||
222 | continue; |
||
223 | } |
||
224 | |||
225 | // Test if permissions are ok |
||
226 | /*$perm=$module->import_permission[$r][0]; |
||
227 | //print_r("$perm[0]-$perm[1]-$perm[2]<br>"); |
||
228 | if ($perm[2]) |
||
229 | { |
||
230 | $bool=$user->rights->{$perm[0]}->{$perm[1]}->{$perm[2]}; |
||
231 | } |
||
232 | else |
||
233 | { |
||
234 | $bool=$user->rights->{$perm[0]}->{$perm[1]}; |
||
235 | } |
||
236 | if ($perm[0]=='user' && $user->admin) $bool=true; |
||
237 | //print $bool." $perm[0]"."<br>"; |
||
238 | */ |
||
239 | |||
240 | // Load lang file |
||
241 | $langtoload = $module->getLangFilesArray(); |
||
242 | if (is_array($langtoload)) { |
||
243 | foreach ($langtoload as $key) { |
||
244 | $langs->load($key); |
||
245 | } |
||
246 | } |
||
247 | |||
248 | // Permission |
||
249 | $this->array_import_perms[$i] = $user->hasRight('import', 'run'); |
||
250 | // Icon |
||
251 | $this->array_import_icon[$i] = (isset($module->import_icon[$r]) ? $module->import_icon[$r] : $module->picto); |
||
252 | // Code of dataset export |
||
253 | $this->array_import_code[$i] = $module->import_code[$r]; |
||
254 | // Label of dataset export |
||
255 | $this->array_import_label[$i] = $module->getImportDatasetLabel($r); |
||
256 | // Array of tables to import (key=alias, value=tablename) |
||
257 | $this->array_import_tables[$i] = $module->import_tables_array[$r]; |
||
258 | // Array of tables creator field to import (key=alias, value=creator field name) |
||
259 | $this->array_import_tables_creator[$i] = (isset($module->import_tables_creator_array[$r]) ? $module->import_tables_creator_array[$r] : ''); |
||
260 | // Array of fields to import (key=field, value=label) |
||
261 | $this->array_import_fields[$i] = $module->import_fields_array[$r]; |
||
262 | // Array of hidden fields to import (key=field, value=label) |
||
263 | $this->array_import_fieldshidden[$i] = (isset($module->import_fieldshidden_array[$r]) ? $module->import_fieldshidden_array[$r] : ''); |
||
264 | // Array of entiteis to export (key=field, value=entity) |
||
265 | $this->array_import_entities[$i] = $module->import_entities_array[$r]; |
||
266 | // Array of aliases to export (key=field, value=alias) |
||
267 | $this->array_import_regex[$i] = (isset($module->import_regex_array[$r]) ? $module->import_regex_array[$r] : ''); |
||
268 | // Array of columns allowed as UPDATE options |
||
269 | $this->array_import_updatekeys[$i] = (isset($module->import_updatekeys_array[$r]) ? $module->import_updatekeys_array[$r] : ''); |
||
270 | // Array of columns preselected as UPDATE options |
||
271 | $this->array_import_preselected_updatekeys[$i] = (isset($module->import_preselected_updatekeys_array[$r]) ? $module->import_preselected_updatekeys_array[$r] : ''); |
||
272 | // Array of examples |
||
273 | $this->array_import_examplevalues[$i] = (isset($module->import_examplevalues_array[$r]) ? $module->import_examplevalues_array[$r] : ''); |
||
274 | // Tableau des regles de conversion d'une valeur depuis une autre source (cle=champ, valeur=tableau des regles) |
||
275 | $this->array_import_convertvalue[$i] = (isset($module->import_convertvalue_array[$r]) ? $module->import_convertvalue_array[$r] : ''); |
||
276 | // Sql request to run after import |
||
277 | $this->array_import_run_sql_after[$i] = (isset($module->import_run_sql_after_array[$r]) ? $module->import_run_sql_after_array[$r] : ''); |
||
278 | // Module |
||
279 | $this->array_import_module[$i] = array('position_of_profile' => ($module->module_position . '-' . $module->import_code[$r]), 'module' => $module); |
||
280 | |||
281 | dol_syslog("Import loaded for module " . $modulename . " with index " . $i . ", dataset=" . $module->import_code[$r] . ", nb of fields=" . count($module->import_fields_array[$r])); |
||
282 | $i++; |
||
283 | } |
||
284 | } |
||
285 | } |
||
286 | closedir($handle); |
||
287 | } |
||
288 | return 1; |
||
289 | } |
||
472 |