Conditions | 7 |
Paths | 2 |
Total Lines | 51 |
Code Lines | 15 |
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 declare(strict_types=1); |
||
37 | public static function &installedAdapters(): array |
||
38 | { |
||
39 | $aAdapters = []; |
||
40 | |||
41 | // Step 1 - directory listing of all files in class/faq/ directory |
||
42 | $adapters_dir = @\dir(\XHELP_FAQ_ADAPTER_PATH); |
||
43 | if ($adapters_dir) { |
||
44 | while (false !== ($file = $adapters_dir->read())) { |
||
45 | if (\preg_match('|^\.+$|', $file)) { |
||
46 | continue; |
||
47 | } |
||
48 | if (\preg_match('|\.php$|', $file)) { |
||
49 | $modname = \basename($file, '.php'); // Get name without file extension |
||
50 | |||
51 | // Step 2 - Check that class exists |
||
52 | // $adapter_data = implode('', file(XHELP_FAQ_ADAPTER_PATH . '/' . $file)); |
||
53 | // $adapter_data = file_get_contents(\XHELP_FAQ_ADAPTER_PATH . '/' . $file); |
||
54 | // $classname = 'xhelp' . \ucfirst($modname) . 'Adapter'; |
||
55 | |||
56 | $class = __NAMESPACE__ . '\Faq\\' . \ucfirst($modname); |
||
57 | if (\class_exists($class)) { |
||
58 | $adapter = new $class(); |
||
59 | if ($adapter instanceof FaqAdapterAbstract) { |
||
60 | // $dirname = $adapter->dirname; |
||
61 | $aAdapters[$modname] = $adapter; |
||
62 | // if (!empty($dirname) && \is_dir(XOOPS_ROOT_PATH . '/modules/' . $dirname)) { |
||
63 | // if ($adapter->loadModule()) { |
||
64 | // $ret = $adapter; |
||
65 | // } else { |
||
66 | // $object->setErrors(\_AM_RSSFIT_PLUGIN_MODNOTFOUND); |
||
67 | // } |
||
68 | // } else { |
||
69 | // $object->setErrors(\_AM_RSSFIT_PLUGIN_MODNOTFOUND); |
||
70 | // } |
||
71 | } |
||
72 | // } else { |
||
73 | // $object->setErrors(\_AM_RSSFIT_PLUGIN_CLASSNOTFOUND . ' ' . $class); |
||
74 | // } |
||
75 | |||
76 | // if (\preg_match("|class $classname(.*)|i", $adapter_data) > 0) { |
||
77 | // require_once \XHELP_FAQ_ADAPTER_PATH . "/$file"; |
||
78 | // $aAdapters[$modname] = new $classname(); |
||
79 | // } |
||
80 | // unset($adapter_data); |
||
81 | } |
||
82 | } |
||
83 | } |
||
84 | } |
||
85 | |||
86 | // Step 3 - return array of accepted filenames |
||
87 | return $aAdapters; |
||
88 | } |
||
184 |