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