Conditions | 34 |
Paths | > 20000 |
Total Lines | 137 |
Code Lines | 72 |
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:
Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.
There are several approaches to avoid long parameter lists:
1 | <?php |
||
81 | protected function renderNormalMenu( |
||
82 | \Zend\Navigation\AbstractContainer $container, |
||
83 | $ulClass, |
||
84 | $indent, |
||
85 | $minDepth, |
||
86 | $maxDepth, |
||
87 | $onlyActive, |
||
88 | $escapeLabels, |
||
89 | $addClassToListItem, |
||
90 | $liActiveClass |
||
91 | ) { |
||
92 | $html = ''; |
||
93 | |||
94 | // find deepest active |
||
95 | $found = $this->findActive($container, $minDepth, $maxDepth); |
||
96 | /* @var $escaper \Zend\View\Helper\EscapeHtmlAttr */ |
||
97 | $escaper = $this->view->plugin('escapeHtmlAttr'); |
||
98 | |||
99 | if ($found) { |
||
100 | $foundPage = $found['page']; |
||
101 | $foundDepth = $found['depth']; |
||
102 | } else { |
||
103 | $foundPage = null; |
||
104 | } |
||
105 | |||
106 | // create iterator |
||
107 | $iterator = new RecursiveIteratorIterator( |
||
108 | $container, |
||
109 | RecursiveIteratorIterator::SELF_FIRST |
||
110 | ); |
||
111 | if (is_int($maxDepth)) { |
||
112 | $iterator->setMaxDepth($maxDepth); |
||
113 | } |
||
114 | |||
115 | // iterate container |
||
116 | $prevDepth = -1; |
||
117 | foreach ($iterator as $page) { |
||
118 | $depth = $iterator->getDepth(); |
||
119 | $page->set('level', $depth); |
||
120 | $isActive = $page->isActive(true); |
||
121 | if ($depth < $minDepth || !$this->accept($page)) { |
||
122 | // page is below minDepth or not accepted by acl/visibility |
||
123 | continue; |
||
124 | } elseif ($onlyActive && !$isActive) { |
||
125 | // page is not active itself, but might be in the active branch |
||
126 | $accept = false; |
||
127 | if ($foundPage) { |
||
128 | if ($foundPage->hasPage($page)) { |
||
129 | // accept if page is a direct child of the active page |
||
130 | $accept = true; |
||
131 | } elseif ($foundPage->getParent()->hasPage($page)) { |
||
132 | // page is a sibling of the active page... |
||
133 | if (!$foundPage->hasPages(!$this->renderInvisible) || |
||
134 | is_int($maxDepth) && $foundDepth + 1 > $maxDepth) { |
||
135 | // accept if active page has no children, or the |
||
136 | // children are too deep to be rendered |
||
137 | $accept = true; |
||
138 | } |
||
139 | } |
||
140 | } |
||
141 | |||
142 | if (!$accept) { |
||
143 | continue; |
||
144 | } |
||
145 | } |
||
146 | |||
147 | // make sure indentation is correct |
||
148 | $depth -= $minDepth; |
||
149 | $myIndent = $indent . str_repeat(' ', $depth); |
||
150 | |||
151 | if ($depth > $prevDepth) { |
||
152 | // start new ul tag |
||
153 | $ulClass = '' . |
||
154 | ($depth == 0 ? $this->getUlClass() : |
||
155 | ($depth == 1 ? $this->getSubUlClassLevel1() : $this->getSubUlClass()) |
||
156 | ) . |
||
157 | ' level_' . $depth . |
||
158 | ''; |
||
159 | if ($ulClass && $depth == 0) { |
||
160 | $ulClass = ' class="' . $escaper($ulClass) . '"'; |
||
161 | } else { |
||
162 | $ulClass = ' class="' . $escaper($ulClass) . '"'; |
||
163 | } |
||
164 | $html .= $myIndent . '<' . $this->getTagname() . $ulClass . '>' . PHP_EOL; |
||
165 | } elseif ($prevDepth > $depth) { |
||
166 | // close li/ul tags until we're at current depth |
||
167 | for ($i = $prevDepth; $i > $depth; $i--) { |
||
168 | $ind = $indent . str_repeat(' ', $i); |
||
169 | //$html .= $ind . ' </li>' . PHP_EOL; |
||
170 | $html .= $ind . '</' . $this->getTagname() . '>' . PHP_EOL; |
||
171 | } |
||
172 | // close previous li tag |
||
173 | //$html .= $myIndent . ' </li>' . PHP_EOL; |
||
174 | } else { |
||
175 | // close previous li tag |
||
176 | //$html .= $myIndent . ' </li>' . PHP_EOL; |
||
177 | } |
||
178 | |||
179 | // render li tag and page |
||
180 | $liClasses = []; |
||
181 | // Is page active? |
||
182 | if ($isActive) { |
||
183 | $liClasses[] = $liActiveClass; |
||
184 | } |
||
185 | if (!empty($this->getDefaultLiClass())) { |
||
186 | $liClasses[] = $this->getDefaultLiClass(); |
||
187 | } |
||
188 | $isBelowMaxLevel = ($maxDepth > $depth) || ($maxDepth === null) || ($maxDepth === false); |
||
189 | if (!empty($page->pages) && $isBelowMaxLevel) { |
||
190 | $liClasses[] = ($depth == 0 ? $this->getSubLiClassLevel0() : $this->getSubLiClass()); |
||
191 | } |
||
192 | // Add CSS class from page to <li> |
||
193 | if ($addClassToListItem && $page->getClass()) { |
||
194 | $liClasses[] = $page->getClass(); |
||
195 | } |
||
196 | $liClass = empty($liClasses) ? '' : ' class="' . $escaper(implode(' ', $liClasses)) . '"'; |
||
197 | |||
198 | $html .= /* $myIndent . ' <li' . $liClass . '>' . PHP_EOL |
||
199 | . */ $myIndent . ' ' . $this->htmlify($page, $escapeLabels, $addClassToListItem, [ |
||
200 | 'data-test' => 'cta-toolbar-' . $this->slugify($page->getLabel()), |
||
201 | ]) . PHP_EOL; |
||
202 | |||
203 | // store as previous depth for next iteration |
||
204 | $prevDepth = $depth; |
||
205 | } |
||
206 | |||
207 | if ($html) { |
||
208 | // done iterating container; close open ul/li tags |
||
209 | for ($i = $prevDepth+1; $i > 0; $i--) { |
||
210 | $myIndent = $indent . str_repeat(' ', $i-1); |
||
211 | $html .= /*$myIndent . ' </li>' . PHP_EOL |
||
212 | . */ $myIndent . '</' . $this->getTagname() . '>' . PHP_EOL; |
||
213 | } |
||
214 | $html = rtrim($html, PHP_EOL); |
||
215 | } |
||
216 | |||
217 | return $html; |
||
218 | } |
||
241 | } |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths