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