| Conditions | 10 |
| Paths | 9 |
| Total Lines | 65 |
| Code Lines | 43 |
| 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 |
||
| 155 | private function printTreeJSON(&$treedata, &$attrs, $print = true) |
||
| 156 | { |
||
| 157 | $parent = []; |
||
| 158 | |||
| 159 | if (isset($attrs['is_root'])) { |
||
| 160 | $parent = [ |
||
| 161 | 'id' => 'root', |
||
| 162 | 'children' => true, |
||
| 163 | 'icon' => \SUBFOLDER . '/assets/images/themes/default/Servers.png', |
||
| 164 | 'state' => ['opened' => true], |
||
| 165 | 'a_attr' => ['href' => \str_replace('//', '/', \SUBFOLDER . '/src/views/servers')], |
||
| 166 | 'url' => \str_replace('//', '/', \SUBFOLDER . '/src/views/servers?action=tree'), |
||
| 167 | 'text' => 'Servers', |
||
| 168 | ]; |
||
| 169 | } elseif (0 < \count($treedata)) { |
||
| 170 | foreach ($treedata as $rec) { |
||
| 171 | $icon = $this->misc->icon(Decorator::get_sanitized_value($attrs['icon'], $rec)); |
||
| 172 | |||
| 173 | if (!empty($attrs['openicon'])) { |
||
| 174 | $icon = $this->misc->icon(Decorator::get_sanitized_value($attrs['openIcon'], $rec)); |
||
| 175 | } |
||
| 176 | |||
| 177 | $tree = [ |
||
| 178 | 'text' => Decorator::get_sanitized_value($attrs['text'], $rec), |
||
| 179 | 'id' => \sha1(Decorator::get_sanitized_value($attrs['action'], $rec)), |
||
| 180 | 'icon' => Decorator::get_sanitized_value($icon, $rec), |
||
| 181 | 'iconaction' => Decorator::get_sanitized_value($attrs['iconAction'], $rec), |
||
| 182 | 'openicon' => Decorator::get_sanitized_value($icon, $rec), |
||
| 183 | 'tooltip' => Decorator::get_sanitized_value($attrs['toolTip'], $rec), |
||
| 184 | 'a_attr' => ['href' => Decorator::get_sanitized_value($attrs['action'], $rec)], |
||
| 185 | 'children' => false, |
||
| 186 | ]; |
||
| 187 | $url = Decorator::get_sanitized_value($attrs['branch'], $rec); |
||
| 188 | |||
| 189 | if ($url && false === \mb_strpos($url, '/src/views')) { |
||
| 190 | $url = \str_replace('//', '/', \SUBFOLDER . '/src/views/' . $url); |
||
| 191 | } |
||
| 192 | |||
| 193 | if ($url) { |
||
| 194 | $tree['url'] = $url; |
||
| 195 | $tree['children'] = true; |
||
| 196 | } |
||
| 197 | |||
| 198 | //$tree['text'] = '<a href="' . $tree['id'] . '" target="detail">' . $tree['text'] . '</a>'; |
||
| 199 | |||
| 200 | $parent[] = $tree; |
||
| 201 | } |
||
| 202 | } else { |
||
| 203 | $parent = ['children' => false]; |
||
| 204 | } |
||
| 205 | |||
| 206 | if (true === $print) { |
||
| 207 | if (isset($_REQUEST['children'])) { |
||
| 208 | $children = $parent; |
||
| 209 | $parent = ['children' => $children]; |
||
| 210 | } |
||
| 211 | |||
| 212 | return $this |
||
| 213 | ->container |
||
| 214 | ->responseobj |
||
| 215 | ->withStatus(200) |
||
| 216 | ->withJson($parent); |
||
| 217 | } |
||
| 218 | |||
| 219 | return $parent; |
||
| 220 | } |
||
| 222 |