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