Conditions | 8 |
Paths | 12 |
Total Lines | 158 |
Code Lines | 79 |
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 |
||
218 | private function printTopbar($do_print = true, $from = null) |
||
1 ignored issue
–
show
|
|||
219 | { |
||
220 | if (null === $from || false === $from) { |
||
221 | $from = __METHOD__; |
||
222 | } |
||
223 | |||
224 | $lang = $this->lang; |
||
225 | $plugin_manager = $this->plugin_manager; |
||
226 | $this->misc = $this->misc; |
||
227 | $appName = $this->misc->appName; |
||
228 | $appVersion = $this->misc->appVersion; |
||
229 | $appLangFiles = $this->misc->appLangFiles; |
||
230 | |||
231 | $server_info = $this->misc->getServerInfo(); |
||
232 | $server_id = $this->misc->getServerId(); |
||
233 | $reqvars = $this->misc->getRequestVars('table'); |
||
234 | |||
235 | $topbar_html = '<div class="topbar" data-controller="'.$this->controller_name.'"><table style="width: 100%"><tr><td>'; |
||
236 | |||
237 | if ($server_info && isset($server_info['platform'], $server_info['username'])) { |
||
238 | // top left informations when connected |
||
239 | $topbar_html .= sprintf( |
||
240 | $lang['strtopbar'], |
||
241 | '<span class="platform">'.htmlspecialchars($server_info['platform']).'</span>', |
||
242 | '<span class="host">'.htmlspecialchars((empty($server_info['host'])) ? 'localhost' : $server_info['host']).'</span>', |
||
243 | '<span class="port">'.htmlspecialchars($server_info['port']).'</span>', |
||
244 | '<span class="username">'.htmlspecialchars($server_info['username']).'</span>' |
||
245 | ); |
||
246 | |||
247 | $topbar_html .= '</td>'; |
||
248 | |||
249 | // top right informations when connected |
||
250 | |||
251 | $toplinks = [ |
||
252 | 'sql' => [ |
||
253 | 'attr' => [ |
||
254 | 'href' => [ |
||
255 | 'url' => SUBFOLDER.'/src/views/sqledit', |
||
256 | 'urlvars' => array_merge($reqvars, [ |
||
1 ignored issue
–
show
|
|||
257 | 'action' => 'sql', |
||
258 | ]), |
||
1 ignored issue
–
show
|
|||
259 | ], |
||
260 | 'target' => 'sqledit', |
||
261 | 'id' => 'toplink_sql', |
||
262 | ], |
||
263 | 'content' => $lang['strsql'], |
||
264 | ], |
||
265 | 'history' => [ |
||
266 | 'attr' => [ |
||
267 | 'href' => [ |
||
268 | 'url' => SUBFOLDER.'/src/views/history', |
||
269 | 'urlvars' => array_merge($reqvars, [ |
||
1 ignored issue
–
show
|
|||
270 | 'action' => 'pophistory', |
||
271 | ]), |
||
1 ignored issue
–
show
|
|||
272 | ], |
||
273 | 'id' => 'toplink_history', |
||
274 | ], |
||
275 | 'content' => $lang['strhistory'], |
||
276 | ], |
||
277 | 'find' => [ |
||
278 | 'attr' => [ |
||
279 | 'href' => [ |
||
280 | 'url' => SUBFOLDER.'/src/views/sqledit', |
||
281 | 'urlvars' => array_merge($reqvars, [ |
||
1 ignored issue
–
show
|
|||
282 | 'action' => 'find', |
||
283 | ]), |
||
1 ignored issue
–
show
|
|||
284 | ], |
||
285 | 'target' => 'sqledit', |
||
286 | 'id' => 'toplink_find', |
||
287 | ], |
||
288 | 'content' => $lang['strfind'], |
||
289 | ], |
||
290 | 'logout' => [ |
||
291 | 'attr' => [ |
||
292 | 'href' => [ |
||
293 | 'url' => SUBFOLDER.'/src/views/servers', |
||
294 | 'urlvars' => [ |
||
295 | 'action' => 'logout', |
||
296 | 'logoutServer' => "{$server_info['host']}:{$server_info['port']}:{$server_info['sslmode']}", |
||
297 | ], |
||
298 | ], |
||
299 | 'id' => 'toplink_logout', |
||
300 | ], |
||
301 | 'content' => $lang['strlogout'], |
||
302 | ], |
||
303 | ]; |
||
304 | |||
305 | // Toplink hook's place |
||
306 | $plugin_functions_parameters = [ |
||
307 | 'toplinks' => &$toplinks, |
||
308 | ]; |
||
309 | |||
310 | $plugin_manager->do_hook('toplinks', $plugin_functions_parameters); |
||
311 | |||
312 | $topbar_html .= '<td style="text-align: right">'; |
||
313 | |||
314 | $topbar_html .= $this->printLinksList($toplinks, 'toplink', [], false, $from); |
||
315 | |||
316 | $topbar_html .= '</td>'; |
||
317 | |||
318 | $sql_window_id = htmlentities('sqledit:'.$server_id); |
||
319 | $history_window_id = htmlentities('history:'.$server_id); |
||
320 | |||
321 | $topbar_html .= "<script type=\"text/javascript\"> |
||
322 | $('#toplink_sql').click(function() { |
||
323 | window.open($(this).attr('href'),'{$sql_window_id}','toolbar=no,width=750,height=520,resizable=yes,scrollbars=yes').focus(); |
||
324 | return false; |
||
325 | }); |
||
326 | |||
327 | $('#toplink_history').click(function() { |
||
328 | window.open($(this).attr('href'),'{$history_window_id}','toolbar=no,width=700,height=500,resizable=yes,scrollbars=yes').focus(); |
||
329 | return false; |
||
330 | }); |
||
331 | |||
332 | $('#toplink_find').click(function() { |
||
333 | window.open($(this).attr('href'),'{$sql_window_id}','toolbar=no,width=750,height=520,resizable=yes,scrollbars=yes').focus(); |
||
334 | return false; |
||
335 | }); |
||
336 | "; |
||
337 | |||
338 | if (isset($_SESSION['sharedUsername'])) { |
||
339 | $topbar_html .= sprintf(" |
||
1 ignored issue
–
show
|
|||
340 | $('#toplink_logout').click(function() { |
||
341 | return confirm('%s'); |
||
342 | });", str_replace("'", "\\'", $lang['strconfdropcred'])); |
||
1 ignored issue
–
show
|
|||
343 | } |
||
344 | |||
345 | $topbar_html .= ' |
||
346 | </script>'; |
||
347 | } else { |
||
348 | $topbar_html .= "<span class=\"appname\">{$appName}</span> <span class=\"version\">{$appVersion}</span>"; |
||
349 | } |
||
350 | /* |
||
351 | echo "<td style=\"text-align: right; width: 1%\">"; |
||
352 | |||
353 | echo "<form method=\"get\"><select name=\"language\" onchange=\"this.form.submit()\">\n"; |
||
354 | $language = isset($_SESSION['webdbLanguage']) ? $_SESSION['webdbLanguage'] : 'english'; |
||
355 | foreach ($appLangFiles as $k => $v) { |
||
356 | echo "<option value=\"{$k}\"", |
||
357 | ($k == $language) ? ' selected="selected"' : '', |
||
358 | ">{$v}</option>\n"; |
||
359 | } |
||
360 | echo "</select>\n"; |
||
361 | echo "<noscript><input type=\"submit\" value=\"Set Language\"></noscript>\n"; |
||
362 | foreach ($_GET as $key => $val) { |
||
363 | if ($key == 'language') continue; |
||
364 | echo "<input type=\"hidden\" name=\"$key\" value=\"", htmlspecialchars($val), "\" />\n"; |
||
365 | } |
||
366 | echo "</form>\n"; |
||
367 | |||
368 | echo "</td>"; |
||
369 | */ |
||
370 | $topbar_html .= "</tr></table></div>\n"; |
||
371 | |||
372 | if ($do_print) { |
||
373 | echo $topbar_html; |
||
374 | } else { |
||
375 | return $topbar_html; |
||
376 | } |
||
604 |