| Conditions | 13 |
| Paths | 10 |
| Total Lines | 123 |
| Code Lines | 87 |
| 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 |
||
| 314 | public function doAlter(bool $confirm = false, $msg = ''): void |
||
| 315 | { |
||
| 316 | $data = $this->misc->getDatabaseAccessor(); |
||
| 317 | |||
| 318 | if ($confirm) { |
||
| 319 | $this->printTrail($this->subject); |
||
| 320 | $this->printTitle($this->lang['stralter'], 'pg.view.alter'); |
||
| 321 | $this->printMsg($msg); |
||
| 322 | |||
| 323 | // Fetch view info |
||
| 324 | $view = $data->getView($_REQUEST[$this->subject]); |
||
| 325 | |||
| 326 | if (0 < $view->recordCount()) { |
||
| 327 | $this->coalesceArr($_POST, 'name', $view->fields['relname']); |
||
| 328 | |||
| 329 | $this->coalesceArr($_POST, 'owner', $view->fields['relowner']); |
||
| 330 | |||
| 331 | $this->coalesceArr($_POST, 'newschema', $view->fields['nspname']); |
||
| 332 | |||
| 333 | $this->coalesceArr($_POST, 'comment', $view->fields['relcomment']); |
||
| 334 | |||
| 335 | echo '<form action="' . \containerInstance()->subFolder . '/src/views/viewproperties" method="post">' . \PHP_EOL; |
||
| 336 | echo '<table>' . \PHP_EOL; |
||
| 337 | echo \sprintf( |
||
| 338 | '<tr><th class="data left required">%s</th>', |
||
| 339 | $this->lang['strname'] |
||
| 340 | ) . \PHP_EOL; |
||
| 341 | echo '<td class="data1">'; |
||
| 342 | echo \sprintf( |
||
| 343 | '<input name="name" size="32" maxlength="%s" value="', |
||
| 344 | $data->_maxNameLen |
||
| 345 | ), |
||
| 346 | \htmlspecialchars($_POST['name']), '" /></td></tr>' . \PHP_EOL; |
||
| 347 | |||
| 348 | if ($data->isSuperUser()) { |
||
| 349 | // Fetch all users |
||
| 350 | $users = $data->getUsers(); |
||
| 351 | |||
| 352 | echo \sprintf( |
||
| 353 | '<tr><th class="data left required">%s</th>', |
||
| 354 | $this->lang['strowner'] |
||
| 355 | ) . \PHP_EOL; |
||
| 356 | echo '<td class="data1"><select name="owner">'; |
||
| 357 | |||
| 358 | while (!$users->EOF) { |
||
| 359 | $uname = $users->fields['usename']; |
||
| 360 | echo '<option value="', \htmlspecialchars($uname), '"', |
||
| 361 | ($uname === $_POST['owner']) ? ' selected="selected"' : '', '>', \htmlspecialchars($uname), '</option>' . \PHP_EOL; |
||
| 362 | $users->moveNext(); |
||
| 363 | } |
||
| 364 | echo '</select></td></tr>' . \PHP_EOL; |
||
| 365 | } |
||
| 366 | |||
| 367 | if ($data->hasAlterTableSchema()) { |
||
| 368 | $schemas = $data->getSchemas(); |
||
| 369 | echo \sprintf( |
||
| 370 | '<tr><th class="data left required">%s</th>', |
||
| 371 | $this->lang['strschema'] |
||
| 372 | ) . \PHP_EOL; |
||
| 373 | echo '<td class="data1"><select name="newschema">'; |
||
| 374 | |||
| 375 | while (!$schemas->EOF) { |
||
| 376 | $schema = $schemas->fields['nspname']; |
||
| 377 | echo '<option value="', \htmlspecialchars($schema), '"', |
||
| 378 | ($schema === $_POST['newschema']) ? ' selected="selected"' : '', '>', \htmlspecialchars($schema), '</option>' . \PHP_EOL; |
||
| 379 | $schemas->moveNext(); |
||
| 380 | } |
||
| 381 | echo '</select></td></tr>' . \PHP_EOL; |
||
| 382 | } |
||
| 383 | |||
| 384 | echo \sprintf( |
||
| 385 | '<tr><th class="data left">%s</th>', |
||
| 386 | $this->lang['strcomment'] |
||
| 387 | ) . \PHP_EOL; |
||
| 388 | echo '<td class="data1">'; |
||
| 389 | echo '<textarea rows="3" cols="32" name="comment">', |
||
| 390 | \htmlspecialchars($_POST['comment']), '</textarea></td></tr>' . \PHP_EOL; |
||
| 391 | echo '</table>' . \PHP_EOL; |
||
| 392 | echo '<input type="hidden" name="action" value="alter" />' . \PHP_EOL; |
||
| 393 | echo '<input type="hidden" name="view" value="', \htmlspecialchars($_REQUEST[$this->subject]), '" />' . \PHP_EOL; |
||
| 394 | echo $this->view->form; |
||
| 395 | echo \sprintf( |
||
| 396 | '<p><input type="submit" name="alter" value="%s" />', |
||
| 397 | $this->lang['stralter'] |
||
| 398 | ) . \PHP_EOL; |
||
| 399 | echo \sprintf( |
||
| 400 | '<input type="submit" name="cancel" value="%s" /></p>%s', |
||
| 401 | $this->lang['strcancel'], |
||
| 402 | \PHP_EOL |
||
| 403 | ); |
||
| 404 | echo '</form>' . \PHP_EOL; |
||
| 405 | } else { |
||
| 406 | echo \sprintf( |
||
| 407 | '<p>%s</p>', |
||
| 408 | $this->lang['strnodata'] |
||
| 409 | ) . \PHP_EOL; |
||
| 410 | } |
||
| 411 | } else { |
||
| 412 | // For databases that don't allow owner change |
||
| 413 | $this->coalesceArr($_POST, 'owner', ''); |
||
| 414 | |||
| 415 | $this->coalesceArr($_POST, 'newschema', null); |
||
| 416 | |||
| 417 | $status = $data->alterView($_POST[$this->subject], $_POST['name'], $_POST['owner'], $_POST['newschema'], $_POST['comment']); |
||
| 418 | |||
| 419 | if (0 === $status) { |
||
| 420 | // If view has been renamed, need to change to the new name and |
||
| 421 | // reload the browser frame. |
||
| 422 | if ($_POST[$this->subject] !== $_POST['name']) { |
||
| 423 | // Jump them to the new view name |
||
| 424 | $_REQUEST[$this->subject] = $_POST['name']; |
||
| 425 | // Force a browser reload |
||
| 426 | $this->view->setReloadBrowser(true); |
||
| 427 | } |
||
| 428 | // If schema has changed, need to change to the new schema and reload the browser |
||
| 429 | if (!empty($_POST['newschema']) && ($_POST['newschema'] !== $data->_schema)) { |
||
| 430 | // Jump them to the new sequence schema |
||
| 431 | $this->misc->setCurrentSchema($_POST['newschema']); |
||
| 432 | $this->view->setReloadBrowser(true); |
||
| 433 | } |
||
| 434 | $this->doDefault($this->lang['strviewaltered']); |
||
| 435 | } else { |
||
| 436 | $this->doAlter(true, $this->lang['strviewalteredbad']); |
||
| 437 | } |
||
| 441 |