Conditions | 12 |
Paths | 73 |
Total Lines | 71 |
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 | foreach ($filteredPages as $page) { |
||
63 | $count++; |
||
64 | $formats = ['html']; |
||
65 | $rendered = null; |
||
66 | $hasAlternates = false; |
||
|
|||
67 | $alternates = []; |
||
68 | |||
69 | // get available formats |
||
70 | if (\is_array($this->config->get('site.output.pagesformats.'.$page->getType()))) { |
||
71 | $formats = $this->config->get('site.output.pagesformats.'.$page->getType()); |
||
72 | } |
||
73 | if (\is_array($page->getVariable('output'))) { |
||
74 | $formats = $page->getVariable('output'); |
||
75 | } |
||
76 | |||
77 | // list alternates |
||
78 | if (count($formats) > 1 && array_key_exists('html', $formats)) { |
||
79 | $hasAlternates = true; |
||
80 | } |
||
81 | foreach ($formats as $format) { |
||
82 | if ($format == 'html') { |
||
83 | continue; |
||
84 | } |
||
85 | $alternates[] = [ |
||
86 | 'rel' => 'alternate', |
||
87 | 'type' => $this->config->get("site.output.formats.$format.mediatype"), |
||
88 | 'title' => strtoupper($format), |
||
89 | 'href' => $page->getPermalink().'/'.$this->config->get("site.output.formats.$format.filename"), |
||
90 | ]; |
||
91 | } |
||
92 | $page->setVariable('alternates', $alternates); |
||
93 | |||
94 | // render each format |
||
95 | foreach ($formats as $format) { |
||
96 | if ($format != 'html' && $page->hasVariable('destination')) { |
||
97 | continue; |
||
98 | } |
||
99 | $layout = (new Layout())->finder($page, $format, $this->config); |
||
100 | $rendered[$format]['output'] = $this->builder->getRenderer()->render( |
||
101 | $layout, |
||
102 | ['page' => $page] |
||
103 | ); |
||
104 | $rendered[$format]['template'] = $layout; |
||
105 | } |
||
106 | $page->setVariable('rendered', $rendered); |
||
107 | $this->builder->getPages()->replace($page->getId(), $page); |
||
108 | |||
109 | $layouts = implode(', ', array_column($rendered, 'template')); |
||
110 | $message = sprintf('%s (%s)', ($page->getId() ?: 'index'), $layouts); |
||
111 | call_user_func_array($this->builder->getMessageCb(), ['RENDER_PROGRESS', $message, $count, $max]); |
||
112 | } |
||
113 | } |
||
114 | |||
164 |
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.