| Conditions | 16 |
| Paths | 83 |
| Total Lines | 69 |
| Code Lines | 52 |
| 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 declare(strict_types=1); |
||
| 97 | public function renderFeed(bool $force_update = false): bool |
||
| 98 | { |
||
| 99 | $retval = false; |
||
| 100 | if ($force_update || $this->headline->cacheExpired()) { |
||
| 101 | if (!$this->updateCache()) { |
||
| 102 | return $retval; |
||
| 103 | } |
||
| 104 | } |
||
| 105 | if ($this->_parse()) { |
||
| 106 | $this->tpl->clear_all_assign(); |
||
| 107 | $this->tpl->assign('xoops_url', XOOPS_URL); |
||
| 108 | $channel_data = $this->parser->getChannelData(); |
||
| 109 | \array_walk($channel_data, [$this, 'convertFromUtf8']); |
||
| 110 | $this->tpl->assign_by_ref('channel', $channel_data); |
||
| 111 | if (1 == $this->headline->getVar('headline_mainimg')) { |
||
| 112 | $image_data = $this->parser->getImageData(); |
||
| 113 | \array_walk($image_data, [$this, 'convertFromUtf8']); |
||
| 114 | $max_width = 256; |
||
| 115 | $max_height = 92; |
||
| 116 | if (!isset($image_data['height']) || !isset($image_data['width'])) { |
||
| 117 | $image_size = @\getimagesize($image_data['url']); |
||
| 118 | if ($image_size) { |
||
| 119 | $image_data['width'] = $image_size[0]; |
||
| 120 | $image_data['height'] = $image_size[1]; |
||
| 121 | } |
||
| 122 | } |
||
| 123 | if (\array_key_exists('height', $image_data) && \array_key_exists('width', $image_data) |
||
| 124 | && ($image_data['width'] > 0)) { |
||
| 125 | $width_ratio = $image_data['width'] / $max_width; |
||
| 126 | $height_ratio = $image_data['height'] / $max_height; |
||
| 127 | $scale = \max($width_ratio, $height_ratio); |
||
| 128 | if ($scale > 1) { |
||
| 129 | $image_data['width'] = (int)($image_data['width'] / $scale); |
||
| 130 | $image_data['height'] = (int)($image_data['height'] / $scale); |
||
| 131 | } |
||
| 132 | } |
||
| 133 | $this->tpl->assign_by_ref('image', $image_data); |
||
| 134 | } |
||
| 135 | if (1 == $this->headline->getVar('headline_mainfull')) { |
||
| 136 | $this->tpl->assign('show_full', true); |
||
| 137 | } else { |
||
| 138 | $this->tpl->assign('show_full', false); |
||
| 139 | } |
||
| 140 | $items = $this->parser->getItems(); |
||
| 141 | $count = \count($items); |
||
| 142 | $max = ($count > $this->headline->getVar('headline_mainmax')) ? $this->headline->getVar('headline_mainmax') : $count; |
||
| 143 | for ($i = 0; $i < $max; ++$i) { |
||
| 144 | \array_walk($items[$i], [$this, 'convertFromUtf8']); |
||
| 145 | $this->tpl->append_by_ref('items', $items[$i]); |
||
| 146 | } |
||
| 147 | $this->tpl->assign( |
||
| 148 | [ |
||
| 149 | 'lang_lastbuild' => \_MD_XOOPSHEADLINE_LASTBUILD, |
||
| 150 | 'lang_language' => \_MD_XOOPSHEADLINE_LANGUAGE, |
||
| 151 | 'lang_description' => \_MD_XOOPSHEADLINE_DESCRIPTION, |
||
| 152 | 'lang_webmaster' => \_MD_XOOPSHEADLINE_WEBMASTER, |
||
| 153 | 'lang_category' => \_MD_XOOPSHEADLINE_CATEGORY, |
||
| 154 | 'lang_generator' => \_MD_XOOPSHEADLINE_GENERATOR, |
||
| 155 | 'lang_title' => \_MD_XOOPSHEADLINE_TITLE, |
||
| 156 | 'lang_pubdate' => \_MD_XOOPSHEADLINE_PUBDATE, |
||
| 157 | // 'lang_description2' => _MD_XOOPSHEADLINE_DESCRIPTION2, |
||
| 158 | 'lang_more' => _MORE, |
||
| 159 | ] |
||
| 160 | ); |
||
| 161 | $this->feed = $this->tpl->fetch('db:xoopsheadline_feed.tpl'); |
||
| 162 | $retval = true; |
||
| 163 | } |
||
| 164 | |||
| 165 | return $retval; |
||
| 166 | } |
||
| 304 |