Conditions | 6 |
Paths | 4 |
Total Lines | 57 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
43 | public function process() |
||
44 | { |
||
45 | // prepares renderer |
||
46 | $this->builder->setRenderer(new Twig($this->getAllLayoutsPaths(), $this->config)); |
||
47 | |||
48 | // add globals variables |
||
49 | $this->addGlobals(); |
||
50 | |||
51 | call_user_func_array($this->builder->getMessageCb(), ['RENDER', 'Rendering pages']); |
||
52 | |||
53 | // collect published pages |
||
54 | /* @var $page Page */ |
||
55 | $filteredPages = $this->builder->getPages()->filter(function (Page $page) { |
||
56 | return !empty($page->getVariable('published')); |
||
57 | }); |
||
58 | $max = count($filteredPages); |
||
59 | |||
60 | // render each page |
||
61 | $count = 0; |
||
62 | /* @var $page Page */ |
||
63 | foreach ($filteredPages as $page) { |
||
64 | $count++; |
||
65 | $formats = ['html']; |
||
|
|||
66 | $rendered = null; |
||
67 | $alternates = []; |
||
68 | |||
69 | // get page's output formats |
||
70 | $formats = $this->getFormats($page); |
||
71 | $page->setVariable('output', $formats); |
||
72 | |||
73 | // get pages's alternates links |
||
74 | $alternates = $this->getAlternates($page, $formats); |
||
75 | $page->setVariable('alternates', $alternates); |
||
76 | |||
77 | // render each output format |
||
78 | foreach ($formats as $format) { |
||
79 | // escape redirect pages |
||
80 | if ($format != 'html' && $page->hasVariable('destination')) { |
||
81 | continue; |
||
82 | } |
||
83 | // search for the template |
||
84 | $layout = Layout::finder($page, $format, $this->config); |
||
85 | // render with Twig |
||
86 | $rendered[$format]['output'] = $this->builder->getRenderer()->render( |
||
87 | $layout, |
||
88 | ['page' => $page] |
||
89 | ); |
||
90 | $rendered[$format]['template'] = $layout; |
||
91 | } |
||
92 | $page->setVariable('rendered', $rendered); |
||
93 | $this->builder->getPages()->replace($page->getId(), $page); |
||
94 | |||
95 | $layouts = implode(', ', array_column($rendered, 'template')); |
||
96 | $message = sprintf('%s (%s)', ($page->getId() ?: 'index'), $layouts); |
||
97 | call_user_func_array($this->builder->getMessageCb(), ['RENDER_PROGRESS', $message, $count, $max]); |
||
98 | } |
||
99 | } |
||
100 | |||
216 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.