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