| Conditions | 17 |
| Paths | 82 |
| Total Lines | 67 |
| Code Lines | 46 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 32 | function b_xlanguage_select_show($options) |
||
| 33 | { |
||
| 34 | global $xlanguage; |
||
| 35 | |||
| 36 | $block = []; |
||
| 37 | |||
| 38 | if (!class_exists(Helper::class)) { |
||
| 39 | // throw new \RuntimeException('Unable to create the $helper directory'); |
||
| 40 | return false; |
||
| 41 | } |
||
| 42 | |||
| 43 | $helper = Helper::getInstance(); |
||
| 44 | $languageHandler = $helper->getHandler('Language'); |
||
| 45 | $languageHandler->loadConfig(); |
||
| 46 | $lang_list = $languageHandler->getAllList(); |
||
| 47 | if (!is_array($lang_list) || (count($lang_list) < 1)) { |
||
|
|
|||
| 48 | return $block; |
||
| 49 | } |
||
| 50 | |||
| 51 | $languages = []; |
||
| 52 | foreach ($lang_list as $lang_name => $lang) { |
||
| 53 | if (!isset($lang['base'])) { |
||
| 54 | continue; |
||
| 55 | } |
||
| 56 | $languages[$lang_name]['name'] = $lang_name; |
||
| 57 | $languages[$lang_name]['desc'] = $lang['base']->getVar('lang_desc'); |
||
| 58 | $languages[$lang_name]['image'] = XOOPS_URL . '/modules/xlanguage/assets/images/' . $lang['base']->getVar('lang_image'); |
||
| 59 | if (!isset($lang['ext']) || count($lang['ext']) < 1) { |
||
| 60 | continue; |
||
| 61 | } |
||
| 62 | foreach ($lang['ext'] as $ext) { |
||
| 63 | $langName = $ext->getVar('lang_name'); |
||
| 64 | $languages[$langName]['name'] = $langName; |
||
| 65 | $languages[$langName]['desc'] = $ext->getVar('lang_desc'); |
||
| 66 | $languages[$langName]['image'] = XOOPS_URL . '/modules/xlanguage/assets/images/' . $ext->getVar('lang_image'); |
||
| 67 | } |
||
| 68 | } |
||
| 69 | |||
| 70 | $QUERY_STRING_array = array_filter(explode('&', xoops_getenv('QUERY_STRING'))); |
||
| 71 | $QUERY_STRING_new = []; |
||
| 72 | foreach ($QUERY_STRING_array as $QUERY) { |
||
| 73 | if (0 !== mb_strpos($QUERY, XLANGUAGE_LANG_TAG . '=')) { |
||
| 74 | $vals = explode('=', $QUERY); |
||
| 75 | foreach (array_keys($vals) as $key) { |
||
| 76 | if (preg_match('/^a-z0-9$/i', $vals[$key])) { |
||
| 77 | $vals[$key] = urlencode($vals[$key]); |
||
| 78 | } |
||
| 79 | } |
||
| 80 | $QUERY_STRING_new[] = implode('=', $vals); |
||
| 81 | } |
||
| 82 | } |
||
| 83 | |||
| 84 | $block['display'] = $options[0]; |
||
| 85 | $block['delimitor'] = $options[1]; |
||
| 86 | $block['number'] = $options[2]; |
||
| 87 | $block['selected'] = $xlanguage['lang']??''; |
||
| 88 | if ('images' === $options[0] || 'text' === $options[0]) { |
||
| 89 | $query_string = htmlspecialchars(implode('&', $QUERY_STRING_new), ENT_QUOTES | ENT_HTML5); |
||
| 90 | $query_string .= empty($query_string) ? '' : '&'; |
||
| 91 | } else { |
||
| 92 | $query_string = implode('&', array_map('\htmlspecialchars', $QUERY_STRING_new)); |
||
| 93 | $query_string .= empty($query_string) ? '' : '&'; |
||
| 94 | } |
||
| 95 | $block['url'] = xoops_getenv('SCRIPT_NAME') . '?' . $query_string . XLANGUAGE_LANG_TAG . '='; |
||
| 96 | $block['languages'] = &$languages; |
||
| 97 | |||
| 98 | return $block; |
||
| 99 | } |
||
| 129 |