Conditions | 13 |
Paths | 10 |
Total Lines | 95 |
Code Lines | 64 |
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 |
||
246 | public function doAlter($confirm = false, $msg = '') |
||
247 | { |
||
248 | $data = $this->misc->getDatabaseAccessor(); |
||
249 | |||
250 | if ($confirm) { |
||
251 | $this->printTrail($this->subject); |
||
252 | $this->printTitle($this->lang['stralter'], 'pg.view.alter'); |
||
253 | $this->printMsg($msg); |
||
254 | |||
255 | // Fetch view info |
||
256 | $view = $data->getView($_REQUEST[$this->subject]); |
||
257 | |||
258 | if ($view->recordCount() > 0) { |
||
259 | $this->coalesceArr($_POST, 'name', $view->fields['relname']); |
||
260 | |||
261 | $this->coalesceArr($_POST, 'owner', $view->fields['relowner']); |
||
262 | |||
263 | $this->coalesceArr($_POST, 'newschema', $view->fields['nspname']); |
||
264 | |||
265 | $this->coalesceArr($_POST, 'comment', $view->fields['relcomment']); |
||
266 | |||
267 | echo '<form action="'.\SUBFOLDER."/src/views/viewproperties\" method=\"post\">\n"; |
||
268 | echo "<table>\n"; |
||
269 | echo "<tr><th class=\"data left required\">{$this->lang['strname']}</th>\n"; |
||
270 | echo '<td class="data1">'; |
||
271 | echo "<input name=\"name\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
272 | htmlspecialchars($_POST['name']), "\" /></td></tr>\n"; |
||
273 | |||
274 | if ($data->isSuperUser()) { |
||
275 | // Fetch all users |
||
276 | $users = $data->getUsers(); |
||
277 | |||
278 | echo "<tr><th class=\"data left required\">{$this->lang['strowner']}</th>\n"; |
||
279 | echo '<td class="data1"><select name="owner">'; |
||
280 | while (!$users->EOF) { |
||
281 | $uname = $users->fields['usename']; |
||
282 | echo '<option value="', htmlspecialchars($uname), '"', |
||
283 | ($uname == $_POST['owner']) ? ' selected="selected"' : '', '>', htmlspecialchars($uname), "</option>\n"; |
||
284 | $users->moveNext(); |
||
285 | } |
||
286 | echo "</select></td></tr>\n"; |
||
287 | } |
||
288 | |||
289 | if ($data->hasAlterTableSchema()) { |
||
290 | $schemas = $data->getSchemas(); |
||
291 | echo "<tr><th class=\"data left required\">{$this->lang['strschema']}</th>\n"; |
||
292 | echo '<td class="data1"><select name="newschema">'; |
||
293 | while (!$schemas->EOF) { |
||
294 | $schema = $schemas->fields['nspname']; |
||
295 | echo '<option value="', htmlspecialchars($schema), '"', |
||
296 | ($schema == $_POST['newschema']) ? ' selected="selected"' : '', '>', htmlspecialchars($schema), "</option>\n"; |
||
297 | $schemas->moveNext(); |
||
298 | } |
||
299 | echo "</select></td></tr>\n"; |
||
300 | } |
||
301 | |||
302 | echo "<tr><th class=\"data left\">{$this->lang['strcomment']}</th>\n"; |
||
303 | echo '<td class="data1">'; |
||
304 | echo '<textarea rows="3" cols="32" name="comment">', |
||
305 | htmlspecialchars($_POST['comment']), "</textarea></td></tr>\n"; |
||
306 | echo "</table>\n"; |
||
307 | echo "<input type=\"hidden\" name=\"action\" value=\"alter\" />\n"; |
||
308 | echo '<input type="hidden" name="view" value="', htmlspecialchars($_REQUEST[$this->subject]), "\" />\n"; |
||
309 | echo $this->misc->form; |
||
310 | echo "<p><input type=\"submit\" name=\"alter\" value=\"{$this->lang['stralter']}\" />\n"; |
||
311 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>\n"; |
||
312 | echo "</form>\n"; |
||
313 | } else { |
||
314 | echo "<p>{$this->lang['strnodata']}</p>\n"; |
||
315 | } |
||
316 | } else { |
||
317 | // For databases that don't allow owner change |
||
318 | $this->coalesceArr($_POST, 'owner', ''); |
||
319 | |||
320 | $this->coalesceArr($_POST, 'newschema', null); |
||
321 | |||
322 | $status = $data->alterView($_POST[$this->subject], $_POST['name'], $_POST['owner'], $_POST['newschema'], $_POST['comment']); |
||
323 | if (0 == $status) { |
||
324 | // If view has been renamed, need to change to the new name and |
||
325 | // reload the browser frame. |
||
326 | if ($_POST[$this->subject] != $_POST['name']) { |
||
327 | // Jump them to the new view name |
||
328 | $_REQUEST[$this->subject] = $_POST['name']; |
||
329 | // Force a browser reload |
||
330 | $this->misc->setReloadBrowser(true); |
||
331 | } |
||
332 | // If schema has changed, need to change to the new schema and reload the browser |
||
333 | if (!empty($_POST['newschema']) && ($_POST['newschema'] != $data->_schema)) { |
||
334 | // Jump them to the new sequence schema |
||
335 | $this->misc->setCurrentSchema($_POST['newschema']); |
||
336 | $this->misc->setReloadBrowser(true); |
||
337 | } |
||
338 | $this->doDefault($this->lang['strviewaltered']); |
||
339 | } else { |
||
340 | $this->doAlter(true, $this->lang['strviewalteredbad']); |
||
341 | } |
||
345 |