| Conditions | 16 |
| Paths | 64 |
| Total Lines | 75 |
| Code Lines | 52 |
| 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 |
||
| 96 | public function printConnection($the_action, $do_print = true) |
||
|
1 ignored issue
–
show
|
|||
| 97 | { |
||
| 98 | $connection_html = "<table class=\"printconnection\" style=\"width: 100%\"><tr><td class=\"popup_select1\">\n"; |
||
| 99 | |||
| 100 | $conf_servers = $this->getServers(); |
||
| 101 | $server_id = $this->misc->getServerId(); |
||
| 102 | $servers = []; |
||
| 103 | foreach ($conf_servers as $key => $info) { |
||
| 104 | if (empty($info['username'])) { |
||
| 105 | continue; |
||
| 106 | } |
||
| 107 | $info['selected'] = ''; |
||
| 108 | if ($this->getRequestParam('server') === $info['id'] || $this->getRequestParam('server') === $key) { |
||
|
1 ignored issue
–
show
|
|||
| 109 | $info['selected'] = ' selected="selected" '; |
||
| 110 | } |
||
| 111 | $servers[$key] = $info; |
||
| 112 | } |
||
| 113 | $connection_html .= '<input type="hidden" readonly="readonly" value="' . $the_action . '" id="the_action">'; |
||
| 114 | |||
| 115 | if (count($servers) === 1) { |
||
| 116 | $connection_html .= '<input type="hidden" readonly="readonly" value="' . $server_id . '" name="server">'; |
||
| 117 | } else { |
||
| 118 | $connection_html .= '<label>'; |
||
| 119 | $connection_html .= $this->misc->printHelp($this->lang['strserver'], 'pg.server', false); |
||
| 120 | $connection_html .= ': </label>'; |
||
| 121 | $connection_html .= " <select name=\"server\" id='selectserver' >\n"; |
||
| 122 | foreach ($servers as $id => $server) { |
||
| 123 | $connection_html .= '<option value="' . $id . '" ' . $server['selected'] . '>'; |
||
| 124 | $connection_html .= htmlspecialchars("{$server['desc']} ({$server['id']})"); |
||
| 125 | $connection_html .= "</option>\n"; |
||
| 126 | } |
||
| 127 | $connection_html .= "</select>\n"; |
||
| 128 | } |
||
| 129 | |||
| 130 | $connection_html .= "</td><td class=\"popup_select2\" style=\"text-align: right\">\n"; |
||
| 131 | |||
| 132 | if (count($servers) === 1 && |
||
| 133 | isset($servers[$server_id]['useonlydefaultdb']) && |
||
| 134 | $servers[$server_id]['useonlydefaultdb'] === true |
||
| 135 | ) { |
||
| 136 | $connection_html .= '<input type="hidden" name="database" value="' . htmlspecialchars($servers[$server_id]['defaultdb']) . "\" />\n"; |
||
| 137 | } else { |
||
| 138 | // Get the list of all databases |
||
| 139 | $data = $this->misc->getDatabaseAccessor(); |
||
| 140 | $databases = $data->getDatabases(); |
||
| 141 | if ($databases->recordCount() > 0) { |
||
| 142 | $connection_html .= '<label>'; |
||
| 143 | $connection_html .= $this->misc->printHelp($this->lang['strdatabase'], 'pg.database', false); |
||
| 144 | $connection_html .= ": <select id='selectdb' name=\"database\" >\n"; |
||
| 145 | |||
| 146 | //if no database was selected, user should select one |
||
| 147 | if (!isset($_REQUEST['database'])) { |
||
| 148 | $connection_html .= "<option value=\"\">--</option>\n"; |
||
| 149 | } |
||
| 150 | |||
| 151 | while (!$databases->EOF) { |
||
| 152 | $dbname = $databases->fields['datname']; |
||
| 153 | $dbselected = isset($_REQUEST['database']) && $dbname == $_REQUEST['database'] ? ' selected="selected"' : ''; |
||
| 154 | $connection_html .= '<option value="' . htmlspecialchars($dbname) . '" ' . $dbselected . '>' . htmlspecialchars($dbname) . "</option>\n"; |
||
| 155 | |||
| 156 | $databases->moveNext(); |
||
| 157 | } |
||
| 158 | $connection_html .= "</select></label>\n"; |
||
| 159 | } else { |
||
| 160 | $server_info = $this->misc->getServerInfo(); |
||
| 161 | $connection_html .= '<input type="hidden" name="database" value="' . htmlspecialchars($server_info['defaultdb']) . "\" />\n"; |
||
| 162 | } |
||
| 163 | } |
||
| 164 | |||
| 165 | $connection_html .= "</td></tr></table>\n"; |
||
| 166 | |||
| 167 | if ($do_print) { |
||
| 168 | echo $connection_html; |
||
| 169 | } else { |
||
| 170 | return $connection_html; |
||
| 171 | } |
||
| 174 |