| Conditions | 10 |
| Paths | 41 |
| Total Lines | 65 |
| Code Lines | 49 |
| 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); |
||
| 29 | function b_news_randomnews_show($options) |
||
| 30 | { |
||
| 31 | /** @var Helper $helper */ |
||
| 32 | if (!class_exists(Helper::class)) { |
||
| 33 | return false; |
||
|
|
|||
| 34 | } |
||
| 35 | |||
| 36 | $helper = Helper::getInstance(); |
||
| 37 | |||
| 38 | $myts = \MyTextSanitizer::getInstance(); |
||
| 39 | $block = []; |
||
| 40 | $block['sort'] = $options[0]; |
||
| 41 | |||
| 42 | $tmpstory = new NewsStory(); |
||
| 43 | $restricted = News\Utility::getModuleOption('restrictindex'); |
||
| 44 | $dateformat = News\Utility::getModuleOption('dateformat'); |
||
| 45 | $infotips = News\Utility::getModuleOption('infotips'); |
||
| 46 | if ('' == $dateformat) { |
||
| 47 | $dateformat = 's'; |
||
| 48 | } |
||
| 49 | if (0 == $options[4]) { |
||
| 50 | $stories = $tmpstory->getRandomNews((int)$options[1], 0, $restricted, 0, 1, $options[0]); |
||
| 51 | } else { |
||
| 52 | $topics = array_slice($options, 4); |
||
| 53 | $stories = $tmpstory->getRandomNews((int)$options[1], 0, $restricted, $topics, 1, $options[0]); |
||
| 54 | } |
||
| 55 | unset($tmpstory); |
||
| 56 | if (0 == count($stories)) { |
||
| 57 | return ''; |
||
| 58 | } |
||
| 59 | foreach ($stories as $story) { |
||
| 60 | $news = []; |
||
| 61 | $title = $story->title(); |
||
| 62 | if (mb_strlen($title) > $options[2]) { |
||
| 63 | $title = xoops_substr($title, 0, $options[2] + 3); |
||
| 64 | } |
||
| 65 | $news['title'] = $title; |
||
| 66 | $news['id'] = $story->storyid(); |
||
| 67 | $news['date'] = formatTimestamp($story->published(), $dateformat); |
||
| 68 | $news['hits'] = $story->counter(); |
||
| 69 | $news['rating'] = $story->rating(); |
||
| 70 | $news['votes'] = $story->votes(); |
||
| 71 | $news['author'] = sprintf('%s %s', _POSTEDBY, $story->uname()); |
||
| 72 | $news['topic_title'] = $story->topic_title(); |
||
| 73 | $news['topic_color'] = '#' . $myts->displayTarea($story->topic_color); |
||
| 74 | $news['picture'] = XOOPS_URL . '/uploads/news/image/' . $story->picture(); |
||
| 75 | $news['pictureinfo'] = $story->pictureinfo(); |
||
| 76 | |||
| 77 | if ($options[3] > 0) { |
||
| 78 | $html = 1 == $story->nohtml() ? 0 : 1; |
||
| 79 | $news['teaser'] = News\Utility::truncateTagSafe($myts->displayTarea($story->hometext, $html), $options[3] + 3); |
||
| 80 | $news['infotips'] = ' title="' . $story->title() . '"'; |
||
| 81 | } else { |
||
| 82 | $news['teaser'] = ''; |
||
| 83 | if ($infotips > 0) { |
||
| 84 | $news['infotips'] = ' title="' . News\Utility::makeInfotips($story->hometext()) . '"'; |
||
| 85 | } else { |
||
| 86 | $news['infotips'] = ' title="' . $story->title() . '"'; |
||
| 87 | } |
||
| 88 | } |
||
| 89 | $block['stories'][] = $news; |
||
| 90 | } |
||
| 91 | $block['lang_read_more'] = _MB_READMORE; |
||
| 92 | |||
| 93 | return $block; |
||
| 94 | } |
||
| 162 |