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 |
||
140 | private function printTreeJSON(&$treedata, &$attrs, $print = true) |
||
141 | { |
||
142 | $parent = []; |
||
143 | |||
144 | if (isset($attrs['is_root'])) { |
||
145 | $parent = [ |
||
146 | 'id' => 'root', |
||
147 | 'children' => true, |
||
148 | 'icon' => \containerInstance()->subFolder . '/assets/images/themes/default/Servers.png', |
||
149 | 'state' => ['opened' => true], |
||
150 | 'a_attr' => ['href' => \str_replace('//', '/', \containerInstance()->subFolder . '/src/views/servers')], |
||
151 | 'url' => \str_replace('//', '/', \containerInstance()->subFolder . '/src/views/servers?action=tree'), |
||
152 | 'text' => 'Servers', |
||
153 | ]; |
||
154 | } elseif (0 < \count($treedata)) { |
||
155 | foreach ($treedata as $rec) { |
||
156 | $icon = $this->view->icon(Decorator::get_sanitized_value($attrs['icon'], $rec)); |
||
157 | |||
158 | if (!empty($attrs['openicon'])) { |
||
159 | $icon = $this->view->icon(Decorator::get_sanitized_value($attrs['openIcon'], $rec)); |
||
160 | } |
||
161 | |||
162 | $tree = [ |
||
163 | 'text' => Decorator::get_sanitized_value($attrs['text'], $rec), |
||
164 | 'id' => \sha1(Decorator::get_sanitized_value($attrs['action'], $rec)), |
||
165 | 'icon' => Decorator::get_sanitized_value($icon, $rec), |
||
166 | 'iconaction' => Decorator::get_sanitized_value($attrs['iconAction'], $rec), |
||
167 | 'openicon' => Decorator::get_sanitized_value($icon, $rec), |
||
168 | 'tooltip' => Decorator::get_sanitized_value($attrs['toolTip'], $rec), |
||
169 | 'a_attr' => ['href' => Decorator::get_sanitized_value($attrs['action'], $rec)], |
||
170 | 'children' => false, |
||
171 | ]; |
||
172 | $url = Decorator::get_sanitized_value($attrs['branch'], $rec); |
||
173 | |||
174 | if ($url && false === \mb_strpos($url, '/src/views')) { |
||
175 | $url = \str_replace('//', '/', \containerInstance()->subFolder . '/src/views/' . $url); |
||
176 | } |
||
177 | |||
178 | if ($url) { |
||
179 | $tree['url'] = $url; |
||
180 | $tree['children'] = true; |
||
181 | } |
||
182 | |||
183 | //$tree['text'] = '<a href="' . $tree['id'] . '" target="detail">' . $tree['text'] . '</a>'; |
||
184 | |||
185 | $parent[] = $tree; |
||
186 | } |
||
187 | } else { |
||
188 | $parent = ['children' => false]; |
||
189 | } |
||
190 | |||
191 | if (true === $print) { |
||
192 | if (isset($_REQUEST['children'])) { |
||
193 | $children = $parent; |
||
194 | $parent = ['children' => $children]; |
||
195 | } |
||
196 | |||
197 | return $this |
||
198 | ->container |
||
199 | ->response |
||
200 | ->withStatus(200) |
||
201 | ->withJson($parent); |
||
202 | } |
||
203 | |||
204 | return $parent; |
||
205 | } |
||
207 |