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