Conditions | 18 |
Paths | 290 |
Total Lines | 59 |
Code Lines | 35 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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 |
||
121 | protected function addItem($currentUri, &$menu, $label, $item, $parent = null) |
||
122 | { |
||
123 | |||
124 | if (isset($item['visibility'])) { |
||
125 | if (isset($item['visibility']['exclude'])) { |
||
126 | $permission = $this->authorizationChecker->isGranted($item['visibility']['exclude'], $this->user); |
||
127 | if ($permission === true) { |
||
128 | return; |
||
129 | } |
||
130 | } else { |
||
131 | $permission = $this->authorizationChecker->isGranted($item['visibility'], $this->user); |
||
132 | if ($permission === false) { |
||
133 | return; |
||
134 | } |
||
135 | } |
||
136 | } |
||
137 | |||
138 | if (isset($item['type']) && isset($item['route']) && $item['type'] == 'route') { |
||
139 | $params = [ |
||
140 | 'route' => $item['route'], |
||
141 | ]; |
||
142 | if (isset($item['parameters'])) { |
||
143 | $params['routeParameters'] = $item['parameters']; |
||
144 | } |
||
145 | } else { |
||
146 | $params = []; |
||
147 | } |
||
148 | |||
149 | if ($parent !== null) { |
||
150 | $menuItem = $parent->addChild($label, $params); |
||
151 | } else { |
||
152 | $menuItem = $menu->addChild($label, $params); |
||
153 | } |
||
154 | |||
155 | if (isset($item['badge']) && isset($this->container)) { |
||
156 | $badge = $this->container->get($item['badge']); |
||
157 | $menuItem->setAttribute('badge', $badge->getCount()); |
||
158 | } |
||
159 | |||
160 | if (!isset($item['route'])) { |
||
161 | $menuItem->setUri('#'); |
||
162 | } |
||
163 | |||
164 | if (!empty($item['icon'])) { |
||
165 | $menuItem->setAttribute('icon', $item['icon']); |
||
166 | } |
||
167 | |||
168 | if (isset($item['children'])) { |
||
169 | $menuItem->setAttribute('class', 'treeview'); |
||
170 | foreach ($item['children'] as $childLabel => $childItem) { |
||
171 | $child = $this->addItem($currentUri, $menu, $childLabel, $childItem, $menuItem); |
||
172 | if ($child !== null && $currentUri == $child->getUri()) { |
||
173 | $this->setParentActive($child->getParent()); |
||
174 | } |
||
175 | } |
||
176 | } |
||
177 | |||
178 | return $menuItem; |
||
179 | } |
||
180 | |||
197 |