diff options
author | ffflabs <amenadiel@gmail.com> | 2020-02-26 10:38:15 +0300 |
---|---|---|
committer | ffflabs <amenadiel@gmail.com> | 2020-02-26 11:30:00 +0300 |
commit | 2b72a6599564901461c9c537e641b58f9fe8cd62 (patch) | |
tree | 5c6a62375a7e0456938792564f64b3b54d0626cc /src/controllers/ViewpropertiesController.php | |
parent | 55f8d1b0a09c9f90eec93e1737f524ecd809ff61 (diff) |
adding psalm linting
fine tuning of git files
restoring tests
fixes tests after refactoring
fine tuning for psalm baseline
Diffstat (limited to 'src/controllers/ViewpropertiesController.php')
-rw-r--r-- | src/controllers/ViewpropertiesController.php | 128 |
1 files changed, 68 insertions, 60 deletions
diff --git a/src/controllers/ViewpropertiesController.php b/src/controllers/ViewpropertiesController.php index 64456bb1..008a36f4 100644 --- a/src/controllers/ViewpropertiesController.php +++ b/src/controllers/ViewpropertiesController.php @@ -1,15 +1,16 @@ <?php +// declare(strict_types=1); + /** - * PHPPgAdmin v6.0.0-RC9 + * PHPPgAdmin vv6.0.0-RC8-16-g13de173f + * */ namespace PHPPgAdmin\Controller; /** * Base controller class. - * - * @package PHPPgAdmin */ class ViewpropertiesController extends BaseController { @@ -17,22 +18,24 @@ class ViewpropertiesController extends BaseController use \PHPPgAdmin\Traits\ViewsMatViewsPropertiesTrait; public $controller_title = 'strviews'; - public $subject = 'view'; + + public $subject = 'view'; /** * Default method to render the controller according to the action parameter. */ public function render() { - if ('tree' == $this->action) { + if ('tree' === $this->action) { return $this->doTree(); } $footer_template = 'footer.twig'; $header_template = 'header.twig'; - ob_start(); + \ob_start(); $this->printFooter(true, $footer_template); + switch ($this->action) { case 'save_edit': if (isset($_POST['cancel'])) { @@ -93,7 +96,7 @@ class ViewpropertiesController extends BaseController break; } - $output = ob_get_clean(); + $output = \ob_get_clean(); $this->printHeader($this->headerTitle('', '', $_REQUEST[$this->subject]), null, true, $header_template); $this->printBody(); @@ -105,12 +108,13 @@ class ViewpropertiesController extends BaseController /** * Function to save after editing a view. */ - public function doSaveEdit() + public function doSaveEdit(): void { $data = $this->misc->getDatabaseAccessor(); $status = $data->setView($_POST[$this->subject], $_POST['formDefinition'], $_POST['formComment']); - if (0 == $status) { + + if (0 === $status) { $this->doDefinition($this->lang['strviewupdated']); } else { $this->doEdit($this->lang['strviewupdatedbad']); @@ -122,7 +126,7 @@ class ViewpropertiesController extends BaseController * * @param mixed $msg */ - public function doEdit($msg = '') + public function doEdit($msg = ''): void { $data = $this->misc->getDatabaseAccessor(); @@ -133,19 +137,19 @@ class ViewpropertiesController extends BaseController $viewdata = $data->getView($_REQUEST[$this->subject]); $this->printHeader($this->headerTitle(), null, true, 'header_sqledit.twig'); - if ($viewdata->recordCount() > 0) { + if (0 < $viewdata->recordCount()) { if (!isset($_POST['formDefinition'])) { $_POST['formDefinition'] = $viewdata->fields['vwdefinition']; $_POST['formComment'] = $viewdata->fields['relcomment']; } $variables = (object) [ - 'subfolder' => \SUBFOLDER.'/src/views/viewproperties', + 'subfolder' => self::SUBFOLDER . '/src/views/viewproperties', - 'formDefinition' => htmlspecialchars($_POST['formDefinition']), + 'formDefinition' => \htmlspecialchars($_POST['formDefinition']), - 'formComment' => htmlspecialchars($_POST['formComment']), - 'subject' => htmlspecialchars($_REQUEST[$this->subject]), ]; + 'formComment' => \htmlspecialchars($_POST['formComment']), + 'subject' => \htmlspecialchars($_REQUEST[$this->subject])]; $edition_area = <<<EOT @@ -179,7 +183,7 @@ class ViewpropertiesController extends BaseController EOT; echo $edition_area; } else { - echo "<p>{$this->lang['strnodata']}</p>".PHP_EOL; + echo "<p>{$this->lang['strnodata']}</p>" . \PHP_EOL; } } @@ -188,7 +192,7 @@ EOT; * * @param mixed $msg */ - public function doProperties($msg = '') + public function doProperties($msg = ''): void { $data = $this->misc->getDatabaseAccessor(); @@ -200,10 +204,10 @@ EOT; $this->printTitle($this->lang['stralter'], 'pg.column.alter'); $this->printMsg($msg); - echo '<form action="'.\SUBFOLDER.'/src/views/viewproperties" method="post">'.PHP_EOL; + echo '<form action="' . self::SUBFOLDER . '/src/views/viewproperties" method="post">' . \PHP_EOL; // Output view header - echo '<table>'.PHP_EOL; + echo '<table>' . \PHP_EOL; echo "<tr><th class=\"data required\">{$this->lang['strname']}</th><th class=\"data required\">{$this->lang['strtype']}</th>"; echo "<th class=\"data\">{$this->lang['strdefault']}</th><th class=\"data\">{$this->lang['strcomment']}</th></tr>"; @@ -216,29 +220,29 @@ EOT; } echo '<tr><td><input name="field" size="32" value="', - htmlspecialchars($_REQUEST['field']), '" /></td>'; + \htmlspecialchars($_REQUEST['field']), '" /></td>'; echo '<td>', $this->misc->printVal($data->formatType($column->fields['type'], $column->fields['atttypmod'])), '</td>'; echo '<td><input name="default" size="20" value="', - htmlspecialchars($_REQUEST['default']), '" /></td>'; + \htmlspecialchars($_REQUEST['default']), '" /></td>'; echo '<td><input name="comment" size="32" value="', - htmlspecialchars($_REQUEST['comment']), '" /></td>'; + \htmlspecialchars($_REQUEST['comment']), '" /></td>'; - echo '</table>'.PHP_EOL; - echo '<p><input type="hidden" name="action" value="properties" />'.PHP_EOL; - echo '<input type="hidden" name="stage" value="2" />'.PHP_EOL; + echo '</table>' . \PHP_EOL; + echo '<p><input type="hidden" name="action" value="properties" />' . \PHP_EOL; + echo '<input type="hidden" name="stage" value="2" />' . \PHP_EOL; echo $this->misc->form; - echo '<input type="hidden" name="view" value="', htmlspecialchars($_REQUEST[$this->subject]), '" />'.PHP_EOL; - echo '<input type="hidden" name="column" value="', htmlspecialchars($_REQUEST['column']), '" />'.PHP_EOL; - echo '<input type="hidden" name="olddefault" value="', htmlspecialchars($_REQUEST['olddefault']), '" />'.PHP_EOL; - echo "<input type=\"submit\" value=\"{$this->lang['stralter']}\" />".PHP_EOL; - echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>".PHP_EOL; - echo '</form>'.PHP_EOL; + echo '<input type="hidden" name="view" value="', \htmlspecialchars($_REQUEST[$this->subject]), '" />' . \PHP_EOL; + echo '<input type="hidden" name="column" value="', \htmlspecialchars($_REQUEST['column']), '" />' . \PHP_EOL; + echo '<input type="hidden" name="olddefault" value="', \htmlspecialchars($_REQUEST['olddefault']), '" />' . \PHP_EOL; + echo "<input type=\"submit\" value=\"{$this->lang['stralter']}\" />" . \PHP_EOL; + echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>" . \PHP_EOL; + echo '</form>' . \PHP_EOL; break; case 2: // Check inputs - if ('' == trim($_REQUEST['field'])) { + if ('' === \trim($_REQUEST['field'])) { $_REQUEST['stage'] = 1; $this->doProperties($this->lang['strcolneedsname']); @@ -260,7 +264,8 @@ EOT; '', $_REQUEST['comment'] ); - if (0 == $status) { + + if (0 === $status) { $this->doDefault($this->lang['strcolumnaltered']); } else { $_REQUEST['stage'] = 1; @@ -271,11 +276,11 @@ EOT; break; default: - echo "<p>{$this->lang['strinvalidparam']}</p>".PHP_EOL; + echo "<p>{$this->lang['strinvalidparam']}</p>" . \PHP_EOL; } } - public function doAlter($confirm = false, $msg = '') + public function doAlter($confirm = false, $msg = ''): void { $data = $this->misc->getDatabaseAccessor(); @@ -287,7 +292,7 @@ EOT; // Fetch view info $view = $data->getView($_REQUEST[$this->subject]); - if ($view->recordCount() > 0) { + if (0 < $view->recordCount()) { $this->coalesceArr($_POST, 'name', $view->fields['relname']); $this->coalesceArr($_POST, 'owner', $view->fields['relowner']); @@ -296,54 +301,56 @@ EOT; $this->coalesceArr($_POST, 'comment', $view->fields['relcomment']); - echo '<form action="'.\SUBFOLDER.'/src/views/viewproperties" method="post">'.PHP_EOL; - echo '<table>'.PHP_EOL; - echo "<tr><th class=\"data left required\">{$this->lang['strname']}</th>".PHP_EOL; + echo '<form action="' . self::SUBFOLDER . '/src/views/viewproperties" method="post">' . \PHP_EOL; + echo '<table>' . \PHP_EOL; + echo "<tr><th class=\"data left required\">{$this->lang['strname']}</th>" . \PHP_EOL; echo '<td class="data1">'; echo "<input name=\"name\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", - htmlspecialchars($_POST['name']), '" /></td></tr>'.PHP_EOL; + \htmlspecialchars($_POST['name']), '" /></td></tr>' . \PHP_EOL; if ($data->isSuperUser()) { // Fetch all users $users = $data->getUsers(); - echo "<tr><th class=\"data left required\">{$this->lang['strowner']}</th>".PHP_EOL; + echo "<tr><th class=\"data left required\">{$this->lang['strowner']}</th>" . \PHP_EOL; echo '<td class="data1"><select name="owner">'; + while (!$users->EOF) { $uname = $users->fields['usename']; - echo '<option value="', htmlspecialchars($uname), '"', - ($uname == $_POST['owner']) ? ' selected="selected"' : '', '>', htmlspecialchars($uname), '</option>'.PHP_EOL; + echo '<option value="', \htmlspecialchars($uname), '"', + ($uname === $_POST['owner']) ? ' selected="selected"' : '', '>', \htmlspecialchars($uname), '</option>' . \PHP_EOL; $users->moveNext(); } - echo '</select></td></tr>'.PHP_EOL; + echo '</select></td></tr>' . \PHP_EOL; } if ($data->hasAlterTableSchema()) { $schemas = $data->getSchemas(); - echo "<tr><th class=\"data left required\">{$this->lang['strschema']}</th>".PHP_EOL; + echo "<tr><th class=\"data left required\">{$this->lang['strschema']}</th>" . \PHP_EOL; echo '<td class="data1"><select name="newschema">'; + while (!$schemas->EOF) { $schema = $schemas->fields['nspname']; - echo '<option value="', htmlspecialchars($schema), '"', - ($schema == $_POST['newschema']) ? ' selected="selected"' : '', '>', htmlspecialchars($schema), '</option>'.PHP_EOL; + echo '<option value="', \htmlspecialchars($schema), '"', + ($schema === $_POST['newschema']) ? ' selected="selected"' : '', '>', \htmlspecialchars($schema), '</option>' . \PHP_EOL; $schemas->moveNext(); } - echo '</select></td></tr>'.PHP_EOL; + echo '</select></td></tr>' . \PHP_EOL; } - echo "<tr><th class=\"data left\">{$this->lang['strcomment']}</th>".PHP_EOL; + echo "<tr><th class=\"data left\">{$this->lang['strcomment']}</th>" . \PHP_EOL; echo '<td class="data1">'; echo '<textarea rows="3" cols="32" name="comment">', - htmlspecialchars($_POST['comment']), '</textarea></td></tr>'.PHP_EOL; - echo '</table>'.PHP_EOL; - echo '<input type="hidden" name="action" value="alter" />'.PHP_EOL; - echo '<input type="hidden" name="view" value="', htmlspecialchars($_REQUEST[$this->subject]), '" />'.PHP_EOL; + \htmlspecialchars($_POST['comment']), '</textarea></td></tr>' . \PHP_EOL; + echo '</table>' . \PHP_EOL; + echo '<input type="hidden" name="action" value="alter" />' . \PHP_EOL; + echo '<input type="hidden" name="view" value="', \htmlspecialchars($_REQUEST[$this->subject]), '" />' . \PHP_EOL; echo $this->misc->form; - echo "<p><input type=\"submit\" name=\"alter\" value=\"{$this->lang['stralter']}\" />".PHP_EOL; - echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>".PHP_EOL; - echo '</form>'.PHP_EOL; + echo "<p><input type=\"submit\" name=\"alter\" value=\"{$this->lang['stralter']}\" />" . \PHP_EOL; + echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>" . \PHP_EOL; + echo '</form>' . \PHP_EOL; } else { - echo "<p>{$this->lang['strnodata']}</p>".PHP_EOL; + echo "<p>{$this->lang['strnodata']}</p>" . \PHP_EOL; } } else { // For databases that don't allow owner change @@ -352,17 +359,18 @@ EOT; $this->coalesceArr($_POST, 'newschema', null); $status = $data->alterView($_POST[$this->subject], $_POST['name'], $_POST['owner'], $_POST['newschema'], $_POST['comment']); - if (0 == $status) { + + if (0 === $status) { // If view has been renamed, need to change to the new name and // reload the browser frame. - if ($_POST[$this->subject] != $_POST['name']) { + if ($_POST[$this->subject] !== $_POST['name']) { // Jump them to the new view name $_REQUEST[$this->subject] = $_POST['name']; // Force a browser reload $this->misc->setReloadBrowser(true); } // If schema has changed, need to change to the new schema and reload the browser - if (!empty($_POST['newschema']) && ($_POST['newschema'] != $data->_schema)) { + if (!empty($_POST['newschema']) && ($_POST['newschema'] !== $data->_schema)) { // Jump them to the new sequence schema $this->misc->setCurrentSchema($_POST['newschema']); $this->misc->setReloadBrowser(true); |