Conditions | 10 |
Paths | 9 |
Total Lines | 62 |
Code Lines | 43 |
Lines | 0 |
Ratio | 0 % |
Changes | 9 | ||
Bugs | 1 | Features | 3 |
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 |
||
107 | private function printTreeJSON(&$treedata, &$attrs, $print = true) |
||
108 | { |
||
109 | $parent = []; |
||
110 | |||
111 | if (isset($attrs['is_root'])) { |
||
112 | $parent = [ |
||
113 | 'id' => 'root', |
||
114 | 'children' => true, |
||
115 | 'icon' => \SUBFOLDER.'/assets/images/themes/default/Servers.png', |
||
116 | 'state' => ['opened' => true], |
||
117 | 'a_attr' => ['href' => str_replace('//', '/', \SUBFOLDER.'/src/views/servers')], |
||
118 | 'url' => str_replace('//', '/', \SUBFOLDER.'/src/views/servers?action=tree'), |
||
119 | 'text' => 'Servers', |
||
120 | ]; |
||
121 | } elseif (count($treedata) > 0) { |
||
122 | foreach ($treedata as $rec) { |
||
123 | $icon = $this->misc->icon(Decorator::get_sanitized_value($attrs['icon'], $rec)); |
||
124 | if (!empty($attrs['openicon'])) { |
||
125 | $icon = $this->misc->icon(Decorator::get_sanitized_value($attrs['openIcon'], $rec)); |
||
126 | } |
||
127 | |||
128 | $tree = [ |
||
129 | 'text' => Decorator::get_sanitized_value($attrs['text'], $rec), |
||
130 | 'id' => sha1(Decorator::get_sanitized_value($attrs['action'], $rec)), |
||
131 | 'icon' => Decorator::get_sanitized_value($icon, $rec), |
||
132 | 'iconaction' => Decorator::get_sanitized_value($attrs['iconAction'], $rec), |
||
133 | 'openicon' => Decorator::get_sanitized_value($icon, $rec), |
||
134 | 'tooltip' => Decorator::get_sanitized_value($attrs['toolTip'], $rec), |
||
135 | 'a_attr' => ['href' => Decorator::get_sanitized_value($attrs['action'], $rec)], |
||
136 | 'children' => false, |
||
137 | ]; |
||
138 | $url = Decorator::get_sanitized_value($attrs['branch'], $rec); |
||
139 | if ($url && strpos($url, '/src/views') === false) { |
||
140 | $url = str_replace('//', '/', \SUBFOLDER.'/src/views/'.$url); |
||
141 | } |
||
142 | if ($url) { |
||
143 | $tree['url'] = $url; |
||
144 | $tree['children'] = true; |
||
145 | } |
||
146 | |||
147 | //$tree['text'] = '<a href="' . $tree['id'] . '" target="detail">' . $tree['text'] . '</a>'; |
||
148 | |||
149 | $parent[] = $tree; |
||
150 | } |
||
151 | } else { |
||
152 | $parent = ['children' => false]; |
||
153 | } |
||
154 | |||
155 | if (true === $print) { |
||
156 | if (isset($_REQUEST['children'])) { |
||
157 | $children = $parent; |
||
158 | $parent = ['children' => $children]; |
||
159 | } |
||
160 | |||
161 | return $this |
||
162 | ->container |
||
163 | ->responseobj |
||
164 | ->withStatus(200) |
||
165 | ->withJson($parent); |
||
166 | } |
||
167 | |||
168 | return $parent; |
||
169 | } |
||
189 |