| Conditions | 11 |
| Paths | 16 |
| Total Lines | 64 |
| 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 |
||
| 44 | * @return array |
||
| 45 | */ |
||
| 46 | function waiting_get_plugin_info($dirname, $language = 'english') |
||
| 47 | { |
||
| 48 | // get $mytrustdirname for D3 modules |
||
| 49 | $mytrustdirname = ''; |
||
| 50 | if (defined('XOOPS_TRUST_PATH') && file_exists(XOOPS_ROOT_PATH . '/modules/' . $dirname . '/mytrustdirname.php')) { |
||
| 51 | @require XOOPS_ROOT_PATH . '/modules/' . $dirname . '/mytrustdirname.php'; |
||
| 52 | } |
||
| 53 | |||
| 54 | $module_plugin_file = XOOPS_ROOT_PATH . '/modules/' . $dirname . '/include/waiting.plugin.php'; |
||
| 55 | $d3module_plugin_file = XOOPS_TRUST_PATH . '/modules/' . $mytrustdirname . '/include/waiting.plugin.php'; |
||
| 56 | $builtin_plugin_file = XOOPS_ROOT_PATH . '/modules/waiting/plugins/' . $dirname . '.php'; |
||
| 57 | |||
| 58 | if (file_exists($module_plugin_file)) { |
||
| 59 | // module side (1st priority) |
||
| 60 | $lang_files = [ |
||
| 61 | XOOPS_ROOT_PATH . "/modules/$dirname/language/$language/waiting.php", |
||
| 62 | XOOPS_ROOT_PATH . "/modules/$dirname/language/english/waiting.php", |
||
| 63 | ]; |
||
| 64 | $langfile_path = ''; |
||
| 65 | foreach ($lang_files as $lang_file) { |
||
| 66 | if (file_exists($lang_file)) { |
||
| 67 | $langfile_path = $lang_file; |
||
| 68 | break; |
||
| 69 | } |
||
| 70 | } |
||
| 71 | $ret = [ |
||
| 72 | 'plugin_path' => $module_plugin_file, |
||
| 73 | 'langfile_path' => $langfile_path, |
||
| 74 | 'func' => 'b_waiting_' . $dirname, |
||
| 75 | 'type' => 'module', |
||
| 76 | ]; |
||
| 77 | } elseif (!empty($mytrustdirname) && file_exists($d3module_plugin_file)) { |
||
|
|
|||
| 78 | // D3 module's plugin under xoops_trust_path (2nd priority) |
||
| 79 | $lang_files = [ |
||
| 80 | XOOPS_TRUST_PATH . "/modules/$mytrustdirname/language/$language/waiting.php", |
||
| 81 | XOOPS_TRUST_PATH . "/modules/$mytrustdirname/language/english/waiting.php", |
||
| 82 | ]; |
||
| 83 | $langfile_path = ''; |
||
| 84 | foreach ($lang_files as $lang_file) { |
||
| 85 | if (file_exists($lang_file)) { |
||
| 86 | $langfile_path = $lang_file; |
||
| 87 | break; |
||
| 88 | } |
||
| 89 | } |
||
| 90 | $ret = [ |
||
| 91 | 'plugin_path' => $d3module_plugin_file, |
||
| 92 | 'langfile_path' => $langfile_path, |
||
| 93 | 'func' => 'b_waiting_' . $mytrustdirname, |
||
| 94 | 'type' => 'module (D3)', |
||
| 95 | ]; |
||
| 96 | } elseif (file_exists($builtin_plugin_file)) { |
||
| 97 | // built-in plugin under modules/waiting (3rd priority) |
||
| 98 | $ret = [ |
||
| 99 | 'plugin_path' => $builtin_plugin_file, |
||
| 100 | 'langfile_path' => '', |
||
| 101 | 'func' => 'b_waiting_' . $dirname, |
||
| 102 | 'type' => 'Waiting', |
||
| 103 | ]; |
||
| 104 | } else { |
||
| 105 | $ret = []; |
||
| 106 | } |
||
| 107 | |||
| 108 | return $ret; |
||
| 110 |