From 449d371367a017015b032c429335e38d65d34547 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Thu, 1 Jun 2023 21:33:14 +0100 Subject: [PATCH 1/5] Redundant condition Signed-off-by: Kamil Tekiela --- phpstan-baseline.neon | 21 ++++++++------------- psalm-baseline.xml | 2 -- src/Components/Expression.php | 2 +- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index a49f1b368..c4f79765c 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -825,6 +825,11 @@ parameters: count: 1 path: src/Utils/Formatter.php + - + message: "#^Binary operation \"&\" between int and int\\|string results in an error\\.$#" + count: 1 + path: src/Utils/Formatter.php + - message: "#^Binary operation \"&\\=\" between array\\\\>\\|bool\\|string\\|null and array\\\\>\\|bool\\|string\\|null results in an error\\.$#" count: 1 @@ -851,12 +856,12 @@ parameters: path: src/Utils/Formatter.php - - message: "#^Access to an undefined property object\\:\\:\\$alias\\.$#" + message: "#^Trying to invoke int\\\\|int\\<1, max\\>\\|non\\-falsy\\-string but it might not be a callable\\.$#" count: 1 - path: src/Utils/Query.php + path: src/Utils/Formatter.php - - message: "#^Access to an undefined property object\\:\\:\\$expr\\.$#" + message: "#^Argument of an invalid type array\\\\|null supplied for foreach, only iterables are supported\\.$#" count: 1 path: src/Utils/Query.php @@ -865,11 +870,6 @@ parameters: count: 1 path: src/Utils/Query.php - - - message: "#^Argument of an invalid type array\\|null supplied for foreach, only iterables are supported\\.$#" - count: 1 - path: src/Utils/Query.php - - message: "#^Cannot access property \\$dest on PhpMyAdmin\\\\SqlParser\\\\Components\\\\IntoKeyword\\|null\\.$#" count: 1 @@ -890,11 +890,6 @@ parameters: count: 1 path: src/Utils/Query.php - - - message: "#^Parameter \\#1 \\$component of static method PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\:\\:build\\(\\) expects array\\\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression, object given\\.$#" - count: 1 - path: src/Utils/Query.php - - message: "#^Cannot access offset 'value' on mixed\\.$#" count: 3 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 303b23a37..903600c9d 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -213,8 +213,6 @@ expr]]> - ! $isExpr - $isExpr $prev[1] !== null function) && ($prev[1] !== null)]]> diff --git a/src/Components/Expression.php b/src/Components/Expression.php index d6f9bb437..efd1eba43 100644 --- a/src/Components/Expression.php +++ b/src/Components/Expression.php @@ -392,7 +392,7 @@ public static function parse(Parser $parser, TokensList $list, array $options = $ret->expr .= $token->token; } - } elseif (! $isExpr) { + } else { if (($token->type === Token::TYPE_OPERATOR) && ($token->value === '.')) { // Found a `.` which means we expect a column name and // the column name we parsed is actually the table name From 51140e4f0c84eb9a46044221f45854f5a85a5020 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Thu, 1 Jun 2023 22:07:27 +0100 Subject: [PATCH 2/5] Remove doubled condition Signed-off-by: Kamil Tekiela --- phpstan-baseline.neon | 5 ----- psalm-baseline.xml | 4 ---- src/Components/OptionsArray.php | 2 +- 3 files changed, 1 insertion(+), 10 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index c4f79765c..a51911473 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -320,11 +320,6 @@ parameters: count: 8 path: src/Components/OptionsArray.php - - - message: "#^Right side of && is always true\\.$#" - count: 1 - path: src/Components/OptionsArray.php - - message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Components\\\\OrderKeyword\\:\\:\\$expr \\(PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\) does not accept PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|null\\.$#" count: 2 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 903600c9d..438d6589e 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -468,10 +468,6 @@ options[$lastOptionId]['expr']->expr]]> - - - - diff --git a/src/Components/OptionsArray.php b/src/Components/OptionsArray.php index e3d6603d4..17c067437 100644 --- a/src/Components/OptionsArray.php +++ b/src/Components/OptionsArray.php @@ -281,7 +281,7 @@ public static function build($component): string $options[] = $option; } else { $options[] = $option['name'] - . (! empty($option['equals']) && $option['equals'] ? '=' : ' ') + . (! empty($option['equals']) ? '=' : ' ') . (! empty($option['expr']) ? $option['expr'] : $option['value']); } } From f9f1e53273b7f4235fde77223b4f1a575693f83d Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Fri, 2 Jun 2023 16:47:35 +0100 Subject: [PATCH 3/5] Fix wrong type hint Signed-off-by: Kamil Tekiela --- phpstan-baseline.neon | 5 ----- psalm-baseline.xml | 6 ------ src/Statement.php | 2 +- 3 files changed, 1 insertion(+), 12 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index a51911473..0bf84818a 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -530,11 +530,6 @@ parameters: count: 1 path: src/Statement.php - - - message: "#^Strict comparison using \\=\\=\\= between class\\-string\\\\|PhpMyAdmin\\\\SqlParser\\\\Component and null will always evaluate to false\\.$#" - count: 1 - path: src/Statement.php - - message: "#^Argument of an invalid type array\\\\|null supplied for foreach, only iterables are supported\\.$#" count: 1 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 438d6589e..4dcbb84b3 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -898,9 +898,6 @@ - - $class === null - $built[$field] value]]]> @@ -934,9 +931,6 @@ bool - - $class !== null - $index diff --git a/src/Statement.php b/src/Statement.php index 42f92b1be..b53a31c40 100644 --- a/src/Statement.php +++ b/src/Statement.php @@ -298,7 +298,7 @@ public function parse(Parser $parser, TokensList $list): void /** * The name of the class that is used for parsing. * - * @var Component + * @var Component|null */ $class = null; From 1cc73946e3845612364675ef44ed16db84bb7987 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Fri, 2 Jun 2023 16:59:20 +0100 Subject: [PATCH 4/5] Remove redundant condition Signed-off-by: Kamil Tekiela --- psalm-baseline.xml | 3 --- src/Utils/Formatter.php | 5 +---- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 4dcbb84b3..660f8037a 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1367,9 +1367,6 @@ options['formats']]]> - - type === Token::TYPE_KEYWORD]]> - diff --git a/src/Utils/Formatter.php b/src/Utils/Formatter.php index ffd202f5d..3f1238383 100644 --- a/src/Utils/Formatter.php +++ b/src/Utils/Formatter.php @@ -440,10 +440,7 @@ public function formatList($list) && empty(self::$inlineClauses[$lastClause]) && ( $curr->type !== Token::TYPE_KEYWORD - || ( - $curr->type === Token::TYPE_KEYWORD - && $curr->flags & Token::FLAG_KEYWORD_FUNCTION - ) + || ($curr->flags & Token::FLAG_KEYWORD_FUNCTION) ) ) { $formattedOptions = true; From ecc447c8bcce78705b226bf7704645cc99c1c188 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Fri, 2 Jun 2023 17:03:03 +0100 Subject: [PATCH 5/5] Swap empty for array check Signed-off-by: Kamil Tekiela --- psalm-baseline.xml | 2 +- src/Utils/Query.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 660f8037a..a47659099 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1421,7 +1421,7 @@ has - + diff --git a/src/Utils/Query.php b/src/Utils/Query.php index 22ca14adf..6268f0238 100644 --- a/src/Utils/Query.php +++ b/src/Utils/Query.php @@ -528,7 +528,7 @@ public static function getAll($query) // If no tables names were found in the SELECT clause or if there // are expressions like * or COUNT(*), etc. tables names should be // extracted from the FROM clause. - if (empty($ret['select_tables'])) { + if ($ret['select_tables'] === []) { foreach ($statement->from as $expr) { if (! isset($expr->table) || ($expr->table === '')) { continue;