| Conditions | 13 |
| Paths | 56 |
| Total Lines | 56 |
| Code Lines | 37 |
| 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 |
||
| 33 | function tagBar($tags, $catid = 0, $modid = 0) |
||
| 34 | { |
||
| 35 | static $loaded, $delimiter; |
||
| 36 | |||
| 37 | if (empty($tags)) { |
||
| 38 | return []; |
||
| 39 | } |
||
| 40 | |||
| 41 | if (null === $loaded) { |
||
| 42 | require_once $GLOBALS['xoops']->path('/modules/tag/include/vars.php'); |
||
| 43 | require_once $GLOBALS['xoops']->path('/modules/tag/include/functions.php'); |
||
| 44 | tag_define_url_delimiter(); |
||
| 45 | if (!($GLOBALS['xoopsModule'] instanceof XoopsModule) |
||
| 46 | || ('tag' !== $GLOBALS['xoopsModule']->getVar('dirname'))) { |
||
| 47 | xoops_loadLanguage('main', 'tag'); |
||
| 48 | } |
||
| 49 | if (file_exists($GLOBALS['xoops']->path('/modules/tag/assets/images/delimiter.gif'))) { |
||
| 50 | $delimiter = "<img src='" . $GLOBALS['xoops']->url('www/modules/tag/assets/images/delimiter.gif') . "' alt=''>"; |
||
| 51 | } else { |
||
| 52 | $delimiter = "<img src='" . $GLOBALS['xoops']->url('www/assets/images/pointer.gif') . "' alt=''>"; |
||
| 53 | } |
||
| 54 | $loaded = 1; |
||
| 55 | } |
||
| 56 | |||
| 57 | // itemid |
||
| 58 | if (is_numeric($tags)) { |
||
| 59 | if (empty($modid) && ($GLOBALS['xoopsModule'] instanceof XoopsModule)) { |
||
| 60 | $modid = $GLOBALS['xoopsModule']->getVar('mid'); |
||
| 61 | } |
||
| 62 | /** @var \XoopsModules\Tag\TagHandler $tagHandler */ |
||
| 63 | $tagHandler = \XoopsModules\Tag\Helper::getInstance()->getHandler('Tag'); // xoops_getModuleHandler('tag', 'tag'); |
||
| 64 | if (!$tags = $tagHandler->getByItem($tags, $modid, $catid)) { |
||
| 65 | return []; |
||
| 66 | } |
||
| 67 | |||
| 68 | // if ready, do nothing |
||
| 69 | } elseif (is_array($tags)) { |
||
|
|
|||
| 70 | // parse |
||
| 71 | } elseif (!$tags = tag_parse_tag($tags)) { |
||
| 72 | return []; |
||
| 73 | } |
||
| 74 | $tags_data = []; |
||
| 75 | foreach ($tags as $tag) { |
||
| 76 | $tags_data[] = "<a href='" |
||
| 77 | . $GLOBALS['xoops']->url('www/modules/' . $GLOBALS['xoopsModule']->getVar('dirname') . '/view.tag.php' . URL_DELIMITER . urlencode($tag)) |
||
| 78 | . "' title='" |
||
| 79 | . htmlspecialchars($tag, ENT_QUOTES | ENT_HTML5) |
||
| 80 | . "'>" |
||
| 81 | . htmlspecialchars($tag, ENT_QUOTES | ENT_HTML5) |
||
| 82 | . '</a>'; |
||
| 83 | } |
||
| 84 | |||
| 85 | return [ |
||
| 86 | 'title' => _MD_TAG_TAGS, |
||
| 87 | 'delimiter' => $delimiter, |
||
| 88 | 'tags' => $tags_data, |
||
| 89 | ]; |
||
| 91 |