diff options
author | ffflabs <amenadiel@gmail.com> | 2020-03-04 22:24:44 +0300 |
---|---|---|
committer | ffflabs <amenadiel@gmail.com> | 2020-03-04 22:24:44 +0300 |
commit | f8cdda8a794ef7f101ee8f55db85d05cde6989f3 (patch) | |
tree | 1ef5684b658d78094f850a0241c316cfbf04229e | |
parent | 06a18bc8866470dadf8ab0478cf3231d0564b01a (diff) |
fixing bugs
-rw-r--r-- | composer.json | 1 | ||||
-rw-r--r-- | phpstan.neon | 29 | ||||
-rw-r--r-- | src/controllers/DisplayController.php | 126 | ||||
-rw-r--r-- | src/decorators/Decorator.php | 12 | ||||
-rw-r--r-- | tests/views/display.php | 21 |
5 files changed, 109 insertions, 80 deletions
diff --git a/composer.json b/composer.json index 42527b80..04c96b3f 100644 --- a/composer.json +++ b/composer.json @@ -59,6 +59,7 @@ } }, "scripts": { + "phpstan": "phpstan analyse src --memory-limit=2G ", "post-install-cmd": "@clear_twig_cache", "post-create-project-cmd": "@clear_twig_cache", "clear_twig_cache": [ diff --git a/phpstan.neon b/phpstan.neon index d78e1c47..408759ac 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,12 +1,16 @@ +#includes: +# - .build/phpstan/phpstan.baseline.neon + parameters: + paths: - src tmpDir: ./.build/phpstan # The level 8 is the highest level - level: 4 + level: 3 autoload_files: - vendor/adodb/adodb-php/adodb.inc.php @@ -18,7 +22,7 @@ parameters: - temp/* - vendor/* - src/classes/ADO* - - router.php + - src/router.php treatPhpDocTypesAsCertain: false @@ -26,6 +30,27 @@ parameters: ignoreErrors: + +# - +# message: "#^Offset '[a-zA-Z0-9_]+' does not exist on array[.*].$#" +# path: src/* + - + message: "#^PHPDoc tag @param references unknown parameter\\: \\$[a-zA-Z0-9_]+$#" + path: src/* + - + message: "#^Access to an undefined property Psr\\\\[a-zA-Z0-9_]+\\\\[a-zA-Z0-9_]+\\:\\:\\$[a-zA-Z0-9_]+\\.$#" + path: src/* + + - + message: "#^Access to an undefined property PHPPgAdmin\\\\[a-zA-Z0-9_]+\\\\[a-zA-Z0-9_]+\\:\\:\\$[a-zA-Z0-9_]+\\.$#" + path: src/* + - + message: "#^Result of method PHPPgAdmin\\\\[a-zA-Z0-9_]+\\\\[a-zA-Z0-9_]+\\:\\:[a-zA-Z0-9_]+\\(\\) \\(void\\) is used\\.$#" + path: src/* + + - + message: "#^Constructor of class [a-zA-Z0-9_]+\\\\[a-zA-Z0-9_]+\\\\[a-zA-Z0-9_]+ has an unused parameter \\$[a-zA-Z0-9_]+\\.$#" + path: src/* #- '#Property [^\s] has no typehint specified#' #- '#Call to an undefined method [a-zA-Z0-9\\_]+::expects\(\)#' #- '#Access to an undefined property PHPPgAdmin::\$[a-zA-Z0-9_]+#' diff --git a/src/controllers/DisplayController.php b/src/controllers/DisplayController.php index 33e11b95..7a8644cc 100644 --- a/src/controllers/DisplayController.php +++ b/src/controllers/DisplayController.php @@ -115,7 +115,7 @@ class DisplayController extends BaseController public function doBrowse($msg = '') { $this->misc = $this->misc; - $data = $this->misc->getDatabaseAccessor(); + $data = $this->misc->getDatabaseAccessor(); // If current page is not set, default to first page $page = $this->coalesceArr($_REQUEST, 'page', 1)['page']; @@ -128,23 +128,23 @@ class DisplayController extends BaseController if ('column' === $subject && $object && isset($_REQUEST['f_schema'], $_REQUEST['f_table'])) { $f_schema = $_REQUEST['f_schema']; - $f_table = $_REQUEST['f_table']; + $f_table = $_REQUEST['f_table']; $_REQUEST['query'] = "SELECT \"{$object}\", count(*) AS \"count\" FROM \"{$f_schema}\".\"{$f_table}\" GROUP BY \"{$object}\" ORDER BY \"{$object}\""; } elseif ('table' === $subject && !isset($_REQUEST['query'])) { - $show = $this->getPostParam('show', []); + $show = $this->getPostParam('show', []); $values = $this->getPostParam('values', []); - $ops = $this->getPostParam('ops', []); - $query = $data->getSelectSQL( + $ops = $this->getPostParam('ops', []); + $query = $data->getSelectSQL( $_REQUEST['table'], \array_keys($show), $values, $ops ); - $_REQUEST['query'] = $query; + $_REQUEST['query'] = $query; $_REQUEST['return'] = 'selectrows'; } @@ -204,7 +204,7 @@ class DisplayController extends BaseController // Build strings for GETs in array $_gets = [ - 'server' => $_REQUEST['server'], + 'server' => $_REQUEST['server'], 'database' => $_REQUEST['database'], ]; @@ -270,20 +270,20 @@ class DisplayController extends BaseController foreach (\array_keys($fkey) as $x) { $ops[$x] = '='; } - $query = $data->getSelectSQL($_REQUEST['table'], [], $fkey, $ops); + $query = $data->getSelectSQL($_REQUEST['table'], [], $fkey, $ops); $_REQUEST['query'] = $query; } $title = 'strqueryresults'; - $type = 'QUERY'; + $type = 'QUERY'; if ($object && $query) { $_SESSION['sqlquery'] = $query; - $title = 'strselect'; - $type = 'SELECT'; + $title = 'strselect'; + $type = 'SELECT'; } elseif ($object) { $title = 'strselect'; - $type = 'TABLE'; + $type = 'TABLE'; } elseif (isset($_SESSION['sqlquery'])) { $query = $_SESSION['sqlquery']; } @@ -297,22 +297,22 @@ class DisplayController extends BaseController public function getBrowseNavLinks($type, array $_gets, $page, $subject, $object, $resultset) { $fields = [ - 'server' => $_REQUEST['server'], + 'server' => $_REQUEST['server'], 'database' => $_REQUEST['database'], ]; $this->setIfIsset($fields['schema'], $_REQUEST['schema'], null, false); $navlinks = []; - $strings = $_gets['strings']; + $strings = $_gets['strings']; // Return if (isset($_REQUEST['return'])) { $urlvars = $this->misc->getSubjectParams($_REQUEST['return']); $navlinks['back'] = [ - 'attr' => [ + 'attr' => [ 'href' => [ - 'url' => $urlvars['url'], + 'url' => $urlvars['url'], 'urlvars' => $urlvars['params'], ], ], @@ -323,13 +323,13 @@ class DisplayController extends BaseController // Edit SQL link if ('QUERY' === $type) { $navlinks['edit'] = [ - 'attr' => [ + 'attr' => [ 'href' => [ - 'url' => 'database', + 'url' => 'database', 'urlvars' => \array_merge( $fields, [ - 'action' => 'sql', + 'action' => 'sql', 'paginate' => 'on', ] ), @@ -340,14 +340,14 @@ class DisplayController extends BaseController } $navlinks['collapse'] = [ - 'attr' => [ + 'attr' => [ 'href' => [ - 'url' => 'display', + 'url' => 'display', 'urlvars' => \array_merge( $_gets, [ 'strings' => 'expanded', - 'page' => $page, + 'page' => $page, ] ), ], @@ -357,14 +357,14 @@ class DisplayController extends BaseController // Expand/Collapse if ('expanded' === $strings) { $navlinks['collapse'] = [ - 'attr' => [ + 'attr' => [ 'href' => [ - 'url' => 'display', + 'url' => 'display', 'urlvars' => \array_merge( $_gets, [ 'strings' => 'collapsed', - 'page' => $page, + 'page' => $page, ] ), ], @@ -378,13 +378,13 @@ class DisplayController extends BaseController // Report views don't set a schema, so we need to disable create view in that case if (isset($_REQUEST['schema'])) { $navlinks['createview'] = [ - 'attr' => [ + 'attr' => [ 'href' => [ - 'url' => 'views', + 'url' => 'views', 'urlvars' => \array_merge( $fields, [ - 'action' => 'create', + 'action' => 'create', 'formDefinition' => $_REQUEST['query'], ] ), @@ -399,9 +399,9 @@ class DisplayController extends BaseController $this->setIfIsset($urlvars['search_path'], $_REQUEST['search_path'], null, false); $navlinks['download'] = [ - 'attr' => [ + 'attr' => [ 'href' => [ - 'url' => 'dataexport', + 'url' => 'dataexport', 'urlvars' => \array_merge($fields, $urlvars), ], ], @@ -412,14 +412,14 @@ class DisplayController extends BaseController // Insert if (isset($object) && (isset($subject) && 'table' === $subject)) { $navlinks['insert'] = [ - 'attr' => [ + 'attr' => [ 'href' => [ - 'url' => 'tables', + 'url' => 'tables', 'urlvars' => \array_merge( $fields, [ 'action' => 'confinsertrow', - 'table' => $object, + 'table' => $object, ] ), ], @@ -430,14 +430,14 @@ class DisplayController extends BaseController // Refresh $navlinks['refresh'] = [ - 'attr' => [ + 'attr' => [ 'href' => [ - 'url' => 'display', + 'url' => 'display', 'urlvars' => \array_merge( $_gets, [ 'strings' => $strings, - 'page' => $page, + 'page' => $page, ] ), ], @@ -483,11 +483,11 @@ class DisplayController extends BaseController \reset($resultset->fields); - $trclass = 'data2'; + $trclass = 'data2'; $buttonclass = 'opbutton2'; while (!$resultset->EOF) { - $trclass = ('data2' === $trclass) ? 'data1' : 'data2'; + $trclass = ('data2' === $trclass) ? 'data1' : 'data2'; $buttonclass = ('opbutton2' === $buttonclass) ? 'opbutton1' : 'opbutton2'; echo \sprintf('<tr class="%s">', $trclass) . \PHP_EOL; @@ -532,7 +532,7 @@ class DisplayController extends BaseController continue; } - $args['page'] = $_REQUEST['page']; + $args['page'] = $_REQUEST['page']; $args['sortkey'] = $index + 1; // Sort direction opposite to current direction, unless it's currently '' $args['sortdir'] = ('asc' === $_REQUEST['sortdir'] && ($index + 1) === $_REQUEST['sortkey']) ? 'desc' : 'asc'; @@ -562,7 +562,7 @@ class DisplayController extends BaseController public function printTableRowCells(&$resultset, &$fkey_information, $withOid): void { $data = $this->misc->getDatabaseAccessor(); - $j = 0; + $j = 0; $this->coalesceArr($_REQUEST, 'strings', 'collapsed'); @@ -604,7 +604,7 @@ class DisplayController extends BaseController $this->printTitle($this->lang['streditrow']); $this->printMsg($msg); - $attrs = $data->getTableAttributes($_REQUEST['table']); + $attrs = $data->getTableAttributes($_REQUEST['table']); $resultset = $data->browseRow($_REQUEST['table'], $key); $fksprops = $this->_getFKProps(); @@ -612,7 +612,7 @@ class DisplayController extends BaseController echo '<form action="' . self::SUBFOLDER . '/src/views/display" method="post" id="ac_form">' . \PHP_EOL; $elements = 0; - $error = true; + $error = true; if (1 === $resultset->recordCount() && 0 < $attrs->recordCount()) { echo '<table>' . \PHP_EOL; @@ -626,7 +626,7 @@ class DisplayController extends BaseController while (!$attrs->EOF) { $attrs->fields['attnotnull'] = $data->phpBool($attrs->fields['attnotnull']); - $id = (0 === ($i % 2) ? '1' : '2'); + $id = (0 === ($i % 2) ? '1' : '2'); // Initialise variables if (!isset($_REQUEST['format'][$attrs->fields['attname']])) { @@ -677,7 +677,7 @@ class DisplayController extends BaseController } if ((false !== $fksprops) && isset($fksprops['byfield'][$attrs->fields['attnum']])) { - $extras['id'] = "attr_{$attrs->fields['attnum']}"; + $extras['id'] = "attr_{$attrs->fields['attnum']}"; $extras['autocomplete'] = 'off'; } @@ -878,8 +878,8 @@ class DisplayController extends BaseController if (!isset($fkey_information['byconstr'][$constr['conid']])) { $fkey_information['byconstr'][$constr['conid']] = [ 'url_data' => 'table=' . \urlencode($constr['f_table']) . '&schema=' . \urlencode($constr['f_schema']), - 'fkeys' => [], - 'consrc' => $constr['consrc'], + 'fkeys' => [], + 'consrc' => $constr['consrc'], ]; } @@ -909,7 +909,7 @@ class DisplayController extends BaseController foreach ($_REQUEST['fkey'] as $x => $y) { $ops[$x] = '='; } - $query = $data->getSelectSQL($_REQUEST['table'], [], $_REQUEST['fkey'], $ops); + $query = $data->getSelectSQL($_REQUEST['table'], [], $_REQUEST['fkey'], $ops); $_REQUEST['query'] = $query; $fkinfo = $this->getFKInfo(); @@ -950,7 +950,7 @@ class DisplayController extends BaseController private function _getKeyAndActions(object $resultset, $object, $data, $page, $_gets) { - $key = []; + $key = []; $strings = $_gets['strings']; // Fetch unique row identifier, if this is a table browse request. @@ -971,16 +971,16 @@ class DisplayController extends BaseController } $buttons = [ - 'edit' => [ + 'edit' => [ 'content' => $this->lang['stredit'], - 'attr' => [ + 'attr' => [ 'href' => [ - 'url' => 'display', + 'url' => 'display', 'urlvars' => \array_merge( [ - 'action' => 'confeditrow', + 'action' => 'confeditrow', 'strings' => $strings, - 'page' => $page, + 'page' => $page, ], $_gets ), @@ -989,14 +989,14 @@ class DisplayController extends BaseController ], 'delete' => [ 'content' => $this->lang['strdelete'], - 'attr' => [ + 'attr' => [ 'href' => [ - 'url' => 'display', + 'url' => 'display', 'urlvars' => \array_merge( [ - 'action' => 'confdelrow', + 'action' => 'confdelrow', 'strings' => $strings, - 'page' => $page, + 'page' => $page, ], $_gets ), @@ -1006,7 +1006,7 @@ class DisplayController extends BaseController ]; $actions = [ 'actionbuttons' => &$buttons, - 'place' => 'display-browse', + 'place' => 'display-browse', ]; foreach (\array_keys($actions['actionbuttons']) as $action) { @@ -1025,11 +1025,11 @@ class DisplayController extends BaseController return; } - $edit_params = $actions['actionbuttons']['edit'] ?? []; + $edit_params = $actions['actionbuttons']['edit'] ?? []; $delete_params = $actions['actionbuttons']['delete'] ?? []; $keys_array = []; - $has_nulls = false; + $has_nulls = false; foreach ($key as $v) { if (null === $resultset->fields[$v]) { @@ -1047,7 +1047,7 @@ class DisplayController extends BaseController } // Display edit and delete links if we have a key if (isset($actions['actionbuttons']['edit'])) { - $actions['actionbuttons']['edit'] = $edit_params; + $actions['actionbuttons']['edit'] = $edit_params; $actions['actionbuttons']['edit']['attr']['href']['urlvars'] = \array_merge( $actions['actionbuttons']['edit']['attr']['href']['urlvars'], $keys_array @@ -1055,7 +1055,7 @@ class DisplayController extends BaseController } if (isset($actions['actionbuttons']['delete'])) { - $actions['actionbuttons']['delete'] = $delete_params; + $actions['actionbuttons']['delete'] = $delete_params; $actions['actionbuttons']['delete']['attr']['href']['urlvars'] = \array_merge( $actions['actionbuttons']['delete']['attr']['href']['urlvars'], $keys_array @@ -1072,7 +1072,7 @@ class DisplayController extends BaseController /** * @param bool[] $printvalOpts */ - private function _printFKLinks(\PHPPgAdmin\ADORecordSet $resultset, array $fkey_information, $k, $v, &array $printvalOpts): void + private function _printFKLinks(\PHPPgAdmin\ADORecordSet $resultset, array $fkey_information, $k, $v, array &$printvalOpts): void { if ((null === $v) || !isset($fkey_information['byfield'][$k])) { return; diff --git a/src/decorators/Decorator.php b/src/decorators/Decorator.php index 36825458..37c791cc 100644 --- a/src/decorators/Decorator.php +++ b/src/decorators/Decorator.php @@ -25,7 +25,7 @@ class Decorator /** * @param null|string $esc */ - public static function get_sanitized_value(&$var, &array $fields, ?string $esc = null) + public static function get_sanitized_value(&$var, array &$fields, ? string $esc = null) { if (\is_a($var, 'PHPPgAdmin\Decorators\Decorator')) { $val = $var->value($fields); @@ -57,7 +57,7 @@ class Decorator * @param \Closure|\Closure|\Closure $callback * @param (mixed|string)[]|null $params */ - public static function callback($callback, ?array $params = null) + public static function callback($callback, ? array $params = null) { return new \PHPPgAdmin\Decorators\CallbackDecorator($callback, $params); } @@ -86,7 +86,7 @@ class Decorator /** * @param array|null $default */ - public static function field(string $fieldName, ?array $default = null) + public static function field(string $fieldName, ? array $default = null) { return new FieldDecorator($fieldName, $default); } @@ -109,7 +109,7 @@ class Decorator /** * @param array|null $vars */ - public static function actionurl(string $base, ?array $vars = null/* ... */) + public static function actionurl(string $base, ? array $vars = null/* ... */) { // If more than one array of vars is given, // use an ArrayMergeDecorator to have them merged @@ -142,14 +142,14 @@ class Decorator /** * @param array|null $vars */ - public static function url(string $base, ?array $vars = null/* ... */) + public static function url(string $base, ? array $vars = null/* ... */) { // If more than one array of vars is given, // use an ArrayMergeDecorator to have them merged // at value evaluation time. if (2 < \func_num_args()) { - $v = \func_get_args(); + $v = \func_get_args(); $base = \array_shift($v); return new UrlDecorator($base, new ArrayMergeDecorator($v)); diff --git a/tests/views/display.php b/tests/views/display.php index 7051e7fd..00eaed5b 100644 --- a/tests/views/display.php +++ b/tests/views/display.php @@ -6,13 +6,16 @@ // Include application functions -function displayFactory($container) { $do_render = false ; -if (!defined('BASE_PATH')) { - require_once '../../src/lib.inc.php'; - $do_render = true; +function displayFactory($container) +{ + $do_render = false; + if (!defined('BASE_PATH')) { + require_once '../../src/lib.inc.php'; + $do_render = true; + } + $controller = new \PHPPgAdmin\Controller\DisplayController($container); + if ($do_render) { + $controller->render(); + } + return $controller; } -$controller = new \PHPPgAdmin\Controller\DisplayController($container); -if ($do_render) { - $controller->render(); -} -return $controller; } |