| Conditions | 19 |
| Paths | 312 |
| Total Lines | 81 |
| Code Lines | 49 |
| 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 |
||
| 162 | public function buildBlock($xobject, &$template) |
||
| 163 | { |
||
| 164 | // The lame type workaround will change |
||
| 165 | // bid is added temporarily as workaround for specific block manipulation |
||
| 166 | $block = array( |
||
| 167 | 'id' => $xobject->getVar('bid'), |
||
| 168 | 'module' => $xobject->getVar('dirname'), |
||
| 169 | 'title' => $xobject->getVar('title'), |
||
| 170 | // 'name' => strtolower( preg_replace( '/[^0-9a-zA-Z_]/', '', str_replace( ' ', '_', $xobject->getVar( 'name' ) ) ) ), |
||
| 171 | 'weight' => $xobject->getVar('weight'), |
||
| 172 | 'lastmod' => $xobject->getVar('last_modified')); |
||
| 173 | |||
| 174 | // title is a comment, don't show it |
||
| 175 | if (0 === strpos($block['title'], '// ')) { |
||
| 176 | $block['title'] = ''; |
||
| 177 | } |
||
| 178 | |||
| 179 | $bcachetime = (int)$xobject->getVar('bcachetime'); |
||
| 180 | if (empty($bcachetime)) { |
||
| 181 | $template->caching = 0; |
||
| 182 | } else { |
||
| 183 | $template->caching = 2; |
||
| 184 | $template->cache_lifetime = $bcachetime; |
||
| 185 | } |
||
| 186 | $template->setCompileId($xobject->getVar('dirname', 'n')); |
||
| 187 | $tplName = ($tplName = $xobject->getVar('template')) ? "db:$tplName" : 'db:system_block_dummy.tpl'; |
||
| 188 | $cacheid = $this->generateCacheId('blk_' . $xobject->getVar('bid')); |
||
| 189 | |||
| 190 | $xoopsLogger = XoopsLogger::getInstance(); |
||
| 191 | if (!$bcachetime || !$template->is_cached($tplName, $cacheid)) { |
||
| 192 | |||
| 193 | //Get theme metas |
||
| 194 | if ($this->theme && $bcachetime) { |
||
| 195 | foreach ($this->theme->metas as $type => $value) { |
||
| 196 | $old[$type] = $this->theme->metas[$type]; |
||
| 197 | } |
||
| 198 | } |
||
| 199 | |||
| 200 | //build block |
||
| 201 | $xoopsLogger->addBlock($xobject->getVar('name')); |
||
| 202 | if ($bresult = $xobject->buildBlock()) { |
||
| 203 | $template->assign('block', $bresult); |
||
| 204 | $block['content'] = $template->fetch($tplName, $cacheid); |
||
| 205 | } else { |
||
| 206 | $block = false; |
||
| 207 | } |
||
| 208 | |||
| 209 | //check if theme added new metas |
||
| 210 | if ($this->theme && $bcachetime) { |
||
| 211 | $metas = array(); |
||
| 212 | foreach ($this->theme->metas as $type => $value) { |
||
| 213 | $dif = array_diff_key($this->theme->metas[$type], $old[$type]); |
||
| 214 | if (count($dif)) { |
||
| 215 | $metas[$type] = $dif; |
||
| 216 | } |
||
| 217 | } |
||
| 218 | if (count($metas)) { |
||
| 219 | xoops_load('xoopscache'); |
||
| 220 | $cache = XoopsCache::getInstance(); |
||
| 221 | $cache->write($cacheid, $metas); |
||
| 222 | } |
||
| 223 | } |
||
| 224 | } else { |
||
| 225 | $xoopsLogger->addBlock($xobject->getVar('name'), true, $bcachetime); |
||
| 226 | $block['content'] = $template->fetch($tplName, $cacheid); |
||
| 227 | } |
||
| 228 | |||
| 229 | //add block cached metas |
||
| 230 | if ($this->theme && $bcachetime) { |
||
| 231 | xoops_load('xoopscache'); |
||
| 232 | $cache = XoopsCache::getInstance(); |
||
| 233 | if ($metas = $cache->read($cacheid)) { |
||
| 234 | foreach ($metas as $type => $value) { |
||
| 235 | $this->theme->metas[$type] = array_merge($this->theme->metas[$type], $metas[$type]); |
||
| 236 | } |
||
| 237 | } |
||
| 238 | } |
||
| 239 | |||
| 240 | $template->setCompileId(); |
||
| 241 | |||
| 242 | return $block; |
||
| 243 | } |
||
| 245 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.