| Conditions | 11 |
| Paths | 194 |
| Total Lines | 47 |
| Code Lines | 26 |
| 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 |
||
| 137 | public function printTree($treeArr = '') |
||
| 138 | { |
||
| 139 | $titleLen = (int)$this->BE_USER->uc['titleLen']; |
||
| 140 | if (!is_array($treeArr)) { |
||
| 141 | $treeArr = $this->tree; |
||
| 142 | } |
||
| 143 | $out = ''; |
||
| 144 | $closeDepth = []; |
||
| 145 | foreach ($treeArr as $treeItem) { |
||
| 146 | $classAttr = ''; |
||
| 147 | if ($treeItem['isFirst']) { |
||
| 148 | $out .= '<ul class="list-tree">'; |
||
| 149 | } |
||
| 150 | |||
| 151 | // Add CSS classes to the list item |
||
| 152 | if ($treeItem['hasSub']) { |
||
| 153 | $classAttr .= ' list-tree-control-open'; |
||
| 154 | } |
||
| 155 | |||
| 156 | $idAttr = htmlspecialchars($this->domIdPrefix . $this->getId($treeItem['row']) . '_' . $treeItem['bank']); |
||
| 157 | $out .= ' |
||
| 158 | <li id="' . $idAttr . '"' . ($classAttr ? ' class="' . trim($classAttr) . '"' : '') . '> |
||
| 159 | <span class="list-tree-group"> |
||
| 160 | <span class="list-tree-icon">' . $treeItem['HTML'] . '</span> |
||
| 161 | <span class="list-tree-title">' . $this->wrapTitle($this->getTitleStr($treeItem['row'], $titleLen), $treeItem['row'], $treeItem['bank']) . '</span> |
||
| 162 | </span>'; |
||
| 163 | |||
| 164 | if (!$treeItem['hasSub']) { |
||
| 165 | $out .= '</li>'; |
||
| 166 | } |
||
| 167 | |||
| 168 | // We have to remember if this is the last one |
||
| 169 | // on level X so the last child on level X+1 closes the <ul>-tag |
||
| 170 | if ($treeItem['isLast']) { |
||
| 171 | $closeDepth[$treeItem['invertedDepth']] = 1; |
||
| 172 | } |
||
| 173 | // If this is the last one and does not have subitems, we need to close |
||
| 174 | // the tree as long as the upper levels have last items too |
||
| 175 | if ($treeItem['isLast'] && !$treeItem['hasSub']) { |
||
| 176 | for ($i = $treeItem['invertedDepth']; $closeDepth[$i] == 1; $i++) { |
||
| 177 | $closeDepth[$i] = 0; |
||
| 178 | $out .= '</ul></li>'; |
||
| 179 | } |
||
| 180 | } |
||
| 181 | } |
||
| 182 | $out = '<ul class="list-tree list-tree-root list-tree-root-clean">' . $out . '</ul>'; |
||
| 183 | return $out; |
||
| 184 | } |
||
| 186 |