From f8b0b7544df893775af416c4c847565851a3095c Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Sat, 10 Jun 2023 00:01:24 +0100 Subject: [PATCH 1/4] Fix ParameterDefinition::build Signed-off-by: Kamil Tekiela --- phpstan-baseline.neon | 14 ++------------ psalm-baseline.xml | 16 ---------------- src/Components/ParameterDefinition.php | 2 +- 3 files changed, 3 insertions(+), 29 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index a49f1b368..0ce05448b 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -335,11 +335,6 @@ parameters: count: 2 path: src/Components/OrderKeyword.php - - - message: "#^Parameter \\#1 \\$component of static method PhpMyAdmin\\\\SqlParser\\\\Components\\\\ParameterDefinition\\:\\:build\\(\\) expects array\\, \\$this\\(PhpMyAdmin\\\\SqlParser\\\\Components\\\\ParameterDefinition\\) given\\.$#" - count: 1 - path: src/Components/ParameterDefinition.php - - message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Components\\\\ParameterDefinition\\:\\:\\$inOut \\(string\\) does not accept string\\|null\\.$#" count: 1 @@ -365,11 +360,6 @@ parameters: count: 2 path: src/Components/ParameterDefinition.php - - - message: "#^Unreachable statement \\- code above always terminates\\.$#" - count: 1 - path: src/Components/ParameterDefinition.php - - message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Components\\\\PartitionDefinition\\:\\:\\$expr \\(PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|string\\) does not accept PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|null\\.$#" count: 1 @@ -596,7 +586,7 @@ parameters: path: src/Statements/CreateStatement.php - - message: "#^Parameter \\#1 \\$component of static method PhpMyAdmin\\\\SqlParser\\\\Components\\\\ParameterDefinition\\:\\:build\\(\\) expects array\\, array\\\\|null given\\.$#" + message: "#^Parameter \\#1 \\$component of static method PhpMyAdmin\\\\SqlParser\\\\Components\\\\ParameterDefinition\\:\\:build\\(\\) expects array\\\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\ParameterDefinition, array\\\\|null given\\.$#" count: 1 path: src/Statements/CreateStatement.php @@ -961,7 +951,7 @@ parameters: path: tests/Builder/CreateStatementTest.php - - message: "#^Parameter \\#1 \\$component of static method PhpMyAdmin\\\\SqlParser\\\\Components\\\\ParameterDefinition\\:\\:build\\(\\) expects array\\, array\\\\|null given\\.$#" + message: "#^Parameter \\#1 \\$component of static method PhpMyAdmin\\\\SqlParser\\\\Components\\\\ParameterDefinition\\:\\:build\\(\\) expects array\\\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\ParameterDefinition, array\\\\|null given\\.$#" count: 2 path: tests/Builder/CreateStatementTest.php diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 303b23a37..e7c09f45a 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -485,24 +485,9 @@ - - $this - - - name]]> - name]]> - - inOut]]> - type]]> - - - inOut]]> - name]]> - type]]> - $component @@ -513,7 +498,6 @@ DataType::parse($parser, $list) - is_array($component) name)]]> diff --git a/src/Components/ParameterDefinition.php b/src/Components/ParameterDefinition.php index b94ee11fb..495d10822 100644 --- a/src/Components/ParameterDefinition.php +++ b/src/Components/ParameterDefinition.php @@ -141,7 +141,7 @@ public static function parse(Parser $parser, TokensList $list, array $options = } /** - * @param ParameterDefinition[] $component the component to be built + * @param ParameterDefinition[]|ParameterDefinition $component the component to be built */ public static function build($component): string { From 6c671e7e96ba55a4f4391b2b40f5591c05de9deb Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Sat, 10 Jun 2023 00:08:53 +0100 Subject: [PATCH 2/4] Fix Condition::build Signed-off-by: Kamil Tekiela --- phpstan-baseline.neon | 10 ---------- psalm-baseline.xml | 15 --------------- src/Components/Condition.php | 2 +- 3 files changed, 1 insertion(+), 26 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 0ce05448b..cf9ca5085 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -75,16 +75,6 @@ parameters: count: 2 path: src/Components/CaseExpression.php - - - message: "#^Parameter \\#1 \\$component of static method PhpMyAdmin\\\\SqlParser\\\\Components\\\\Condition\\:\\:build\\(\\) expects array\\, \\$this\\(PhpMyAdmin\\\\SqlParser\\\\Components\\\\Condition\\) given\\.$#" - count: 1 - path: src/Components/Condition.php - - - - message: "#^Unreachable statement \\- code above always terminates\\.$#" - count: 1 - path: src/Components/Condition.php - - message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Components\\\\CreateDefinition\\:\\:\\$name \\(string\\|null\\) does not accept mixed\\.$#" count: 2 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index e7c09f45a..0d5e4bdb4 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -128,30 +128,15 @@ - - $this - value]]]> - - string - - - expr]]> - - - expr]]> - $component $isOperator - - is_array($component) - diff --git a/src/Components/Condition.php b/src/Components/Condition.php index cbb5a7371..462c6d70f 100644 --- a/src/Components/Condition.php +++ b/src/Components/Condition.php @@ -221,7 +221,7 @@ public static function parse(Parser $parser, TokensList $list, array $options = } /** - * @param Condition[] $component the component to be built + * @param Condition[]|Condition $component the component to be built */ public static function build($component): string { From 286557ad5e1fcbfcc0866fc5cb5a88065b467648 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Sat, 10 Jun 2023 00:54:12 +0100 Subject: [PATCH 3/4] We do not test invalid assumptions Signed-off-by: Kamil Tekiela --- phpstan-baseline.neon | 5 ----- psalm-baseline.xml | 5 ----- src/Components/WithKeyword.php | 4 ---- tests/Parser/WithStatementTest.php | 7 ------- 4 files changed, 21 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index cf9ca5085..083fe16f6 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1050,11 +1050,6 @@ parameters: count: 1 path: tests/Parser/SelectStatementTest.php - - - message: "#^Parameter \\#1 \\$component of static method PhpMyAdmin\\\\SqlParser\\\\Components\\\\WithKeyword\\:\\:build\\(\\) expects PhpMyAdmin\\\\SqlParser\\\\Components\\\\WithKeyword, stdClass given\\.$#" - count: 1 - path: tests/Parser/WithStatementTest.php - - message: "#^Parameter \\#2 \\$list of static method PhpMyAdmin\\\\SqlParser\\\\Utils\\\\Query\\:\\:getClause\\(\\) expects PhpMyAdmin\\\\SqlParser\\\\TokensList, PhpMyAdmin\\\\SqlParser\\\\TokensList\\|null given\\.$#" count: 9 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 0d5e4bdb4..1fb72626a 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1628,11 +1628,6 @@ has - - - new stdClass() - - $data diff --git a/src/Components/WithKeyword.php b/src/Components/WithKeyword.php index 03df14795..4b92d53e2 100644 --- a/src/Components/WithKeyword.php +++ b/src/Components/WithKeyword.php @@ -50,10 +50,6 @@ public static function parse(Parser $parser, TokensList $list, array $options = */ public static function build($component): string { - if (! $component instanceof WithKeyword) { - throw new RuntimeException('Can not build a component that is not a WithKeyword'); - } - if (! isset($component->statement)) { throw new RuntimeException('No statement inside WITH'); } diff --git a/tests/Parser/WithStatementTest.php b/tests/Parser/WithStatementTest.php index 6e2ac18bf..7356be37e 100644 --- a/tests/Parser/WithStatementTest.php +++ b/tests/Parser/WithStatementTest.php @@ -8,7 +8,6 @@ use PhpMyAdmin\SqlParser\Lexer; use PhpMyAdmin\SqlParser\Parser; use PhpMyAdmin\SqlParser\Tests\TestCase; -use stdClass; class WithStatementTest extends TestCase { @@ -134,12 +133,6 @@ public function testWithHasUnclosedParenthesis(): void $this->assertEquals($parserErrors[0][0], 'A closing bracket was expected.'); } - public function testBuildWrongWithKeyword(): void - { - $this->expectExceptionMessage('Can not build a component that is not a WithKeyword'); - WithKeyword::build(new stdClass()); - } - public function testBuildBadWithKeyword(): void { $this->expectExceptionMessage('No statement inside WITH'); From bb7a7f622b2e9527b8bf574bec0a9bf5d53fc94d Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Sat, 22 Jul 2023 15:45:56 +0100 Subject: [PATCH 4/4] Update phpstan-baseline.neon Signed-off-by: Kamil Tekiela --- phpstan-baseline.neon | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 083fe16f6..2e1f82a82 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -805,6 +805,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 @@ -831,12 +836,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 @@ -845,11 +850,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 @@ -870,11 +870,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