| Conditions | 9 |
| Paths | 10 |
| Total Lines | 67 |
| 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 |
||
| 119 | protected function collectPages() |
||
| 120 | { |
||
| 121 | $count = 0; |
||
| 122 | |||
| 123 | $filteredPages = $this->builder->getPages() |
||
| 124 | ->filter(function (Page $page) |
||
| 125 | { |
||
| 126 | if ($page->getVariable('menu')) { |
||
| 127 | return true; |
||
| 128 | } |
||
| 129 | }); |
||
| 130 | |||
| 131 | $total = count($filteredPages); |
||
| 132 | |||
| 133 | if ($total > 0) { |
||
| 134 | call_user_func_array($this->builder->getMessageCb(), ['MENU', 'Creating menus (pages)']); |
||
| 135 | } |
||
| 136 | |||
| 137 | /* @var $page \Cecil\Collection\Page\Page */ |
||
| 138 | foreach ($filteredPages as $page) { |
||
| 139 | $count++; |
||
| 140 | /* |
||
| 141 | * Single case |
||
| 142 | * ie: |
||
| 143 | * menu: main |
||
| 144 | */ |
||
| 145 | if (is_string($page->getVariable('menu'))) { |
||
| 146 | $item = (new Entry($page->getId())) |
||
| 147 | ->setName($page->getVariable('title')) |
||
| 148 | ->setUrl($page->getUrl()); |
||
| 149 | /* @var $menu \Cecil\Collection\Menu\Menu */ |
||
| 150 | $menu = $page->getVariable('menu'); |
||
| 151 | if (!$this->menus->has($menu)) { |
||
| 152 | $this->menus->add(new Menu($menu)); |
||
| 153 | } |
||
| 154 | $this->menus->get($menu)->add($item); |
||
| 155 | } else { |
||
| 156 | /* |
||
| 157 | * Multiple case |
||
| 158 | * ie: |
||
| 159 | * menu: |
||
| 160 | * main: |
||
| 161 | * weight: 999 |
||
| 162 | * other |
||
| 163 | */ |
||
| 164 | if (is_array($page->getVariable('menu'))) { |
||
| 165 | foreach ($page->getVariable('menu') as $menu => $property) { |
||
| 166 | $item = (new Entry($page->getId())) |
||
| 167 | ->setName($page->getVariable('title')) |
||
| 168 | ->setUrl($page->getId()) |
||
| 169 | ->setWeight($property['weight']); |
||
| 170 | /* @var $menu \Cecil\Collection\Menu\Menu */ |
||
| 171 | if (!$this->menus->has($menu)) { |
||
| 172 | $this->menus->add(new Menu($menu)); |
||
| 173 | } |
||
| 174 | $this->menus->get($menu)->add($item); |
||
| 175 | } |
||
| 176 | } |
||
| 177 | } |
||
| 178 | call_user_func_array($this->builder->getMessageCb(), [ |
||
| 179 | 'MENU_PROGRESS', |
||
| 180 | sprintf('%s > %s', $menu, $page->getId()), |
||
| 181 | $count, |
||
| 182 | $total |
||
| 183 | ]); |
||
| 184 | } |
||
| 185 | } |
||
| 186 | } |
||
| 187 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.