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