| Conditions | 10 |
| Paths | 9 |
| Total Lines | 90 |
| Code Lines | 55 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 197 | protected function render_blocks () { |
||
| 198 | $blocks = Config::instance()->components['blocks']; |
||
| 199 | /** |
||
| 200 | * It is frequent that there is no blocks - so, no need to to anything here |
||
| 201 | */ |
||
| 202 | if (!$blocks) { |
||
| 203 | return; |
||
| 204 | } |
||
| 205 | $Page = Page::instance(); |
||
| 206 | $blocks_array = [ |
||
| 207 | 'top' => '', |
||
| 208 | 'left' => '', |
||
| 209 | 'right' => '', |
||
| 210 | 'bottom' => '' |
||
| 211 | ]; |
||
| 212 | foreach ($blocks as $block) { |
||
| 213 | /** |
||
| 214 | * If there is no need to show block or it was rendered by even handler - skip further processing |
||
| 215 | */ |
||
| 216 | if ( |
||
| 217 | !$this->should_block_be_rendered($block) || |
||
| 218 | !Event::instance()->fire( |
||
| 219 | 'System/Index/block_render', |
||
| 220 | [ |
||
| 221 | 'index' => $block['index'], |
||
| 222 | 'blocks_array' => &$blocks_array |
||
| 223 | ] |
||
| 224 | ) || |
||
| 225 | !Event::instance()->fire( |
||
| 226 | 'System/App/block_render', |
||
| 227 | [ |
||
| 228 | 'index' => $block['index'], |
||
| 229 | 'blocks_array' => &$blocks_array |
||
| 230 | ] |
||
| 231 | ) |
||
| 232 | ) { |
||
| 233 | /** |
||
| 234 | * Block was rendered by event handler |
||
| 235 | */ |
||
| 236 | continue; |
||
| 237 | } |
||
| 238 | $block['title'] = $this->ml_process($block['title']); |
||
| 239 | switch ($block['type']) { |
||
| 240 | default: |
||
| 241 | $block['content'] = ob_wrapper( |
||
| 242 | function () use ($block) { |
||
| 243 | include BLOCKS."/block.$block[type].php"; |
||
| 244 | } |
||
| 245 | ); |
||
| 246 | break; |
||
| 247 | case 'html': |
||
| 248 | case 'raw_html': |
||
| 249 | $block['content'] = $this->ml_process($block['content']); |
||
| 250 | break; |
||
| 251 | } |
||
| 252 | /** |
||
| 253 | * Template file will have access to `$block` variable, so it can use that |
||
| 254 | */ |
||
| 255 | $content = str_replace( |
||
| 256 | [ |
||
| 257 | '<!--id-->', |
||
| 258 | '<!--title-->', |
||
| 259 | '<!--content-->' |
||
| 260 | ], |
||
| 261 | [ |
||
| 262 | $block['index'], |
||
| 263 | $block['title'], |
||
| 264 | $block['content'] |
||
| 265 | ], |
||
| 266 | ob_wrapper( |
||
| 267 | function () use ($block) { |
||
| 268 | $template = file_exists(TEMPLATES."/blocks/block.$block[template]") ? $block['template'] : 'default.html'; |
||
| 269 | include TEMPLATES."/blocks/block.$template"; |
||
| 270 | } |
||
| 271 | ) |
||
| 272 | ); |
||
| 273 | if ($block['position'] == 'floating') { |
||
| 274 | $Page->replace( |
||
| 275 | "<!--block#$block[index]-->", |
||
| 276 | $content |
||
| 277 | ); |
||
| 278 | } else { |
||
| 279 | $blocks_array[$block['position']] .= $content; |
||
| 280 | } |
||
| 281 | } |
||
| 282 | $Page->Top .= $blocks_array['top']; |
||
| 283 | $Page->Left .= $blocks_array['left']; |
||
| 284 | $Page->Right .= $blocks_array['right']; |
||
| 285 | $Page->Bottom .= $blocks_array['bottom']; |
||
| 286 | } |
||
| 287 | /** |
||
| 326 |