| Conditions | 9 |
| Paths | 14 |
| Total Lines | 64 |
| Code Lines | 45 |
| 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 |
||
| 116 | protected function addNavigationLinks(PagesCollection $pages, string $sort = null, $circular = false): void |
||
| 117 | { |
||
| 118 | $pagesAsArray = $pages->toArray(); |
||
| 119 | if ($sort === null || $sort == 'date') { |
||
| 120 | $pagesAsArray = array_reverse($pagesAsArray); |
||
| 121 | } |
||
| 122 | $count = count($pagesAsArray); |
||
| 123 | if ($count > 1) { |
||
| 124 | foreach ($pagesAsArray as $position => $page) { |
||
| 125 | switch ($position) { |
||
| 126 | // first |
||
| 127 | case 0: |
||
| 128 | if ($circular) { |
||
| 129 | $page->setVariables([ |
||
| 130 | 'prev' => [ |
||
| 131 | 'id' => $pagesAsArray[$count - 1]->getId(), |
||
| 132 | 'path' => $pagesAsArray[$count - 1]->getPath(), |
||
| 133 | 'title' => $pagesAsArray[$count - 1]->getVariable('title'), |
||
| 134 | ], |
||
| 135 | ]); |
||
| 136 | } |
||
| 137 | $page->setVariables([ |
||
| 138 | 'next' => [ |
||
| 139 | 'id' => $pagesAsArray[$position + 1]->getId(), |
||
| 140 | 'path' => $pagesAsArray[$position + 1]->getPath(), |
||
| 141 | 'title' => $pagesAsArray[$position + 1]->getVariable('title'), |
||
| 142 | ], |
||
| 143 | ]); |
||
| 144 | break; |
||
| 145 | // last |
||
| 146 | case $count - 1: |
||
| 147 | $page->setVariables([ |
||
| 148 | 'prev' => [ |
||
| 149 | 'id' => $pagesAsArray[$position - 1]->getId(), |
||
| 150 | 'path' => $pagesAsArray[$position - 1]->getPath(), |
||
| 151 | 'title' => $pagesAsArray[$position - 1]->getVariable('title'), |
||
| 152 | ], |
||
| 153 | ]); |
||
| 154 | if ($circular) { |
||
| 155 | $page->setVariables([ |
||
| 156 | 'next' => [ |
||
| 157 | 'id' => $pagesAsArray[0]->getId(), |
||
| 158 | 'path' => $pagesAsArray[0]->getPath(), |
||
| 159 | 'title' => $pagesAsArray[0]->getVariable('title'), |
||
| 160 | ], |
||
| 161 | ]); |
||
| 162 | } |
||
| 163 | break; |
||
| 164 | default: |
||
| 165 | $page->setVariables([ |
||
| 166 | 'prev' => [ |
||
| 167 | 'id' => $pagesAsArray[$position - 1]->getId(), |
||
| 168 | 'path' => $pagesAsArray[$position - 1]->getPath(), |
||
| 169 | 'title' => $pagesAsArray[$position - 1]->getVariable('title'), |
||
| 170 | ], |
||
| 171 | 'next' => [ |
||
| 172 | 'id' => $pagesAsArray[$position + 1]->getId(), |
||
| 173 | 'path' => $pagesAsArray[$position + 1]->getPath(), |
||
| 174 | 'title' => $pagesAsArray[$position + 1]->getVariable('title'), |
||
| 175 | ], |
||
| 176 | ]); |
||
| 177 | break; |
||
| 178 | } |
||
| 179 | $this->generatedPages->add($page); |
||
| 180 | } |
||
| 184 |