| 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 |
||
| 117 | public function printTree($treeArr = '') |
||
| 118 | { |
||
| 119 | $titleLen = (int)$this->getBackendUser()->uc['titleLen']; |
||
| 120 | if (!is_array($treeArr)) { |
||
| 121 | $treeArr = $this->tree; |
||
| 122 | } |
||
| 123 | $out = ''; |
||
| 124 | $closeDepth = []; |
||
| 125 | foreach ($treeArr as $treeItem) { |
||
| 126 | $classAttr = ''; |
||
| 127 | if ($treeItem['isFirst']) { |
||
| 128 | $out .= '<ul class="list-tree">'; |
||
| 129 | } |
||
| 130 | |||
| 131 | // Add CSS classes to the list item |
||
| 132 | if ($treeItem['hasSub']) { |
||
| 133 | $classAttr .= ' list-tree-control-open'; |
||
| 134 | } |
||
| 135 | |||
| 136 | $idAttr = htmlspecialchars('pages' . $treeItem['row']['uid'] . '_' . $treeItem['bank']); |
||
| 137 | $out .= ' |
||
| 138 | <li id="' . $idAttr . '"' . ($classAttr ? ' class="' . trim($classAttr) . '"' : '') . '> |
||
| 139 | <span class="list-tree-group"> |
||
| 140 | <span class="list-tree-icon">' . $treeItem['HTML'] . '</span> |
||
| 141 | <span class="list-tree-title">' . $this->wrapTitle($this->getTitleStr($treeItem['row'], $titleLen)) . '</span> |
||
| 142 | </span>'; |
||
| 143 | |||
| 144 | if (!$treeItem['hasSub']) { |
||
| 145 | $out .= '</li>'; |
||
| 146 | } |
||
| 147 | |||
| 148 | // We have to remember if this is the last one |
||
| 149 | // on level X so the last child on level X+1 closes the <ul>-tag |
||
| 150 | if ($treeItem['isLast']) { |
||
| 151 | $closeDepth[$treeItem['invertedDepth']] = 1; |
||
| 152 | } |
||
| 153 | // If this is the last one and does not have subitems, we need to close |
||
| 154 | // the tree as long as the upper levels have last items too |
||
| 155 | if ($treeItem['isLast'] && !$treeItem['hasSub']) { |
||
| 156 | for ($i = $treeItem['invertedDepth']; $closeDepth[$i] == 1; $i++) { |
||
| 157 | $closeDepth[$i] = 0; |
||
| 158 | $out .= '</ul></li>'; |
||
| 159 | } |
||
| 160 | } |
||
| 161 | } |
||
| 162 | $out = '<ul class="list-tree list-tree-root list-tree-root-clean">' . $out . '</ul>'; |
||
| 163 | return $out; |
||
| 164 | } |
||
| 166 |