| Conditions | 13 |
| Paths | 10 |
| Total Lines | 98 |
| Code Lines | 64 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 |
||
| 281 | public function doAlter(bool $confirm = false, $msg = ''): void |
||
| 282 | { |
||
| 283 | $data = $this->misc->getDatabaseAccessor(); |
||
| 284 | |||
| 285 | if ($confirm) { |
||
| 286 | $this->printTrail($this->subject); |
||
| 287 | $this->printTitle($this->lang['stralter'], 'pg.view.alter'); |
||
| 288 | $this->printMsg($msg); |
||
| 289 | |||
| 290 | // Fetch view info |
||
| 291 | $view = $data->getView($_REQUEST[$this->subject]); |
||
| 292 | |||
| 293 | if (0 < $view->recordCount()) { |
||
| 294 | $this->coalesceArr($_POST, 'name', $view->fields['relname']); |
||
| 295 | |||
| 296 | $this->coalesceArr($_POST, 'owner', $view->fields['relowner']); |
||
| 297 | |||
| 298 | $this->coalesceArr($_POST, 'newschema', $view->fields['nspname']); |
||
| 299 | |||
| 300 | $this->coalesceArr($_POST, 'comment', $view->fields['relcomment']); |
||
| 301 | |||
| 302 | echo '<form action="' . \containerInstance()->subFolder . '/src/views/viewproperties" method="post">' . \PHP_EOL; |
||
| 303 | echo '<table>' . \PHP_EOL; |
||
| 304 | echo "<tr><th class=\"data left required\">{$this->lang['strname']}</th>" . \PHP_EOL; |
||
| 305 | echo '<td class="data1">'; |
||
| 306 | echo "<input name=\"name\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
| 307 | \htmlspecialchars($_POST['name']), '" /></td></tr>' . \PHP_EOL; |
||
| 308 | |||
| 309 | if ($data->isSuperUser()) { |
||
| 310 | // Fetch all users |
||
| 311 | $users = $data->getUsers(); |
||
| 312 | |||
| 313 | echo "<tr><th class=\"data left required\">{$this->lang['strowner']}</th>" . \PHP_EOL; |
||
| 314 | echo '<td class="data1"><select name="owner">'; |
||
| 315 | |||
| 316 | while (!$users->EOF) { |
||
| 317 | $uname = $users->fields['usename']; |
||
| 318 | echo '<option value="', \htmlspecialchars($uname), '"', |
||
| 319 | ($uname === $_POST['owner']) ? ' selected="selected"' : '', '>', \htmlspecialchars($uname), '</option>' . \PHP_EOL; |
||
| 320 | $users->moveNext(); |
||
| 321 | } |
||
| 322 | echo '</select></td></tr>' . \PHP_EOL; |
||
| 323 | } |
||
| 324 | |||
| 325 | if ($data->hasAlterTableSchema()) { |
||
| 326 | $schemas = $data->getSchemas(); |
||
| 327 | echo "<tr><th class=\"data left required\">{$this->lang['strschema']}</th>" . \PHP_EOL; |
||
| 328 | echo '<td class="data1"><select name="newschema">'; |
||
| 329 | |||
| 330 | while (!$schemas->EOF) { |
||
| 331 | $schema = $schemas->fields['nspname']; |
||
| 332 | echo '<option value="', \htmlspecialchars($schema), '"', |
||
| 333 | ($schema === $_POST['newschema']) ? ' selected="selected"' : '', '>', \htmlspecialchars($schema), '</option>' . \PHP_EOL; |
||
| 334 | $schemas->moveNext(); |
||
| 335 | } |
||
| 336 | echo '</select></td></tr>' . \PHP_EOL; |
||
| 337 | } |
||
| 338 | |||
| 339 | echo "<tr><th class=\"data left\">{$this->lang['strcomment']}</th>" . \PHP_EOL; |
||
| 340 | echo '<td class="data1">'; |
||
| 341 | echo '<textarea rows="3" cols="32" name="comment">', |
||
| 342 | \htmlspecialchars($_POST['comment']), '</textarea></td></tr>' . \PHP_EOL; |
||
| 343 | echo '</table>' . \PHP_EOL; |
||
| 344 | echo '<input type="hidden" name="action" value="alter" />' . \PHP_EOL; |
||
| 345 | echo '<input type="hidden" name="view" value="', \htmlspecialchars($_REQUEST[$this->subject]), '" />' . \PHP_EOL; |
||
| 346 | echo $this->view->form; |
||
| 347 | echo "<p><input type=\"submit\" name=\"alter\" value=\"{$this->lang['stralter']}\" />" . \PHP_EOL; |
||
| 348 | echo \sprintf('<input type="submit" name="cancel" value="%s" /></p>%s', $this->lang['strcancel'], \PHP_EOL); |
||
| 349 | echo '</form>' . \PHP_EOL; |
||
| 350 | } else { |
||
| 351 | echo "<p>{$this->lang['strnodata']}</p>" . \PHP_EOL; |
||
| 352 | } |
||
| 353 | } else { |
||
| 354 | // For databases that don't allow owner change |
||
| 355 | $this->coalesceArr($_POST, 'owner', ''); |
||
| 356 | |||
| 357 | $this->coalesceArr($_POST, 'newschema', null); |
||
| 358 | |||
| 359 | $status = $data->alterView($_POST[$this->subject], $_POST['name'], $_POST['owner'], $_POST['newschema'], $_POST['comment']); |
||
| 360 | |||
| 361 | if (0 === $status) { |
||
| 362 | // If view has been renamed, need to change to the new name and |
||
| 363 | // reload the browser frame. |
||
| 364 | if ($_POST[$this->subject] !== $_POST['name']) { |
||
| 365 | // Jump them to the new view name |
||
| 366 | $_REQUEST[$this->subject] = $_POST['name']; |
||
| 367 | // Force a browser reload |
||
| 368 | $this->view->setReloadBrowser(true); |
||
| 369 | } |
||
| 370 | // If schema has changed, need to change to the new schema and reload the browser |
||
| 371 | if (!empty($_POST['newschema']) && ($_POST['newschema'] !== $data->_schema)) { |
||
| 372 | // Jump them to the new sequence schema |
||
| 373 | $this->misc->setCurrentSchema($_POST['newschema']); |
||
| 374 | $this->view->setReloadBrowser(true); |
||
| 375 | } |
||
| 376 | $this->doDefault($this->lang['strviewaltered']); |
||
| 377 | } else { |
||
| 378 | $this->doAlter(true, $this->lang['strviewalteredbad']); |
||
| 379 | } |
||
| 383 |