Skip to content

Fix build method param types #481

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 10 additions & 40 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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\\<PhpMyAdmin\\\\SqlParser\\\\Components\\\\Condition\\>, \\$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
Expand Down Expand Up @@ -335,11 +325,6 @@ parameters:
count: 2
path: src/Components/OrderKeyword.php

-
message: "#^Parameter \\#1 \\$component of static method PhpMyAdmin\\\\SqlParser\\\\Components\\\\ParameterDefinition\\:\\:build\\(\\) expects array\\<PhpMyAdmin\\\\SqlParser\\\\Components\\\\ParameterDefinition\\>, \\$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
Expand All @@ -365,11 +350,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
Expand Down Expand Up @@ -596,7 +576,7 @@ parameters:
path: src/Statements/CreateStatement.php

-
message: "#^Parameter \\#1 \\$component of static method PhpMyAdmin\\\\SqlParser\\\\Components\\\\ParameterDefinition\\:\\:build\\(\\) expects array\\<PhpMyAdmin\\\\SqlParser\\\\Components\\\\ParameterDefinition\\>, array\\<PhpMyAdmin\\\\SqlParser\\\\Components\\\\ParameterDefinition\\>\\|null given\\.$#"
message: "#^Parameter \\#1 \\$component of static method PhpMyAdmin\\\\SqlParser\\\\Components\\\\ParameterDefinition\\:\\:build\\(\\) expects array\\<PhpMyAdmin\\\\SqlParser\\\\Components\\\\ParameterDefinition\\>\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\ParameterDefinition, array\\<PhpMyAdmin\\\\SqlParser\\\\Components\\\\ParameterDefinition\\>\\|null given\\.$#"
count: 1
path: src/Statements/CreateStatement.php

Expand Down Expand Up @@ -825,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\\<int, array\\<string, int\\|string\\>\\>\\|bool\\|string\\|null and array\\<int, array\\<string, int\\|string\\>\\>\\|bool\\|string\\|null results in an error\\.$#"
count: 1
Expand All @@ -851,12 +836,12 @@ parameters:
path: src/Utils/Formatter.php

-
message: "#^Access to an undefined property object\\:\\:\\$alias\\.$#"
message: "#^Trying to invoke int\\<min, \\-1\\>\\|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\\<PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|string\\|null\\>\\|null supplied for foreach, only iterables are supported\\.$#"
count: 1
path: src/Utils/Query.php

Expand All @@ -865,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
Expand All @@ -890,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\\>\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression, object given\\.$#"
count: 1
path: src/Utils/Query.php

-
message: "#^Cannot access offset 'value' on mixed\\.$#"
count: 3
Expand Down Expand Up @@ -961,7 +936,7 @@ parameters:
path: tests/Builder/CreateStatementTest.php

-
message: "#^Parameter \\#1 \\$component of static method PhpMyAdmin\\\\SqlParser\\\\Components\\\\ParameterDefinition\\:\\:build\\(\\) expects array\\<PhpMyAdmin\\\\SqlParser\\\\Components\\\\ParameterDefinition\\>, array\\<PhpMyAdmin\\\\SqlParser\\\\Components\\\\ParameterDefinition\\>\\|null given\\.$#"
message: "#^Parameter \\#1 \\$component of static method PhpMyAdmin\\\\SqlParser\\\\Components\\\\ParameterDefinition\\:\\:build\\(\\) expects array\\<PhpMyAdmin\\\\SqlParser\\\\Components\\\\ParameterDefinition\\>\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\ParameterDefinition, array\\<PhpMyAdmin\\\\SqlParser\\\\Components\\\\ParameterDefinition\\>\\|null given\\.$#"
count: 2
path: tests/Builder/CreateStatementTest.php

Expand Down Expand Up @@ -1070,11 +1045,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
Expand Down
36 changes: 0 additions & 36 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,30 +128,15 @@
</MoreSpecificImplementedParamType>
</file>
<file src="src/Components/Condition.php">
<InvalidArgument>
<code>$this</code>
</InvalidArgument>
<MixedArrayOffset>
<code><![CDATA[static::$allowedKeywords[$token->value]]]></code>
</MixedArrayOffset>
<MixedInferredReturnType>
<code>string</code>
</MixedInferredReturnType>
<MixedPropertyFetch>
<code><![CDATA[$component->expr]]></code>
</MixedPropertyFetch>
<MixedReturnStatement>
<code><![CDATA[$component->expr]]></code>
</MixedReturnStatement>
<MoreSpecificImplementedParamType>
<code>$component</code>
</MoreSpecificImplementedParamType>
<PossiblyUnusedProperty>
<code>$isOperator</code>
</PossiblyUnusedProperty>
<RedundantConditionGivenDocblockType>
<code>is_array($component)</code>
</RedundantConditionGivenDocblockType>
</file>
<file src="src/Components/CreateDefinition.php">
<MixedAssignment>
Expand Down Expand Up @@ -485,24 +470,9 @@
</PossiblyNullPropertyAssignmentValue>
</file>
<file src="src/Components/ParameterDefinition.php">
<InvalidArgument>
<code>$this</code>
</InvalidArgument>
<MixedArgument>
<code><![CDATA[$component->name]]></code>
</MixedArgument>
<MixedAssignment>
<code><![CDATA[$expr->name]]></code>
</MixedAssignment>
<MixedOperand>
<code><![CDATA[$component->inOut]]></code>
<code><![CDATA[$component->type]]></code>
</MixedOperand>
<MixedPropertyFetch>
<code><![CDATA[$component->inOut]]></code>
<code><![CDATA[$component->name]]></code>
<code><![CDATA[$component->type]]></code>
</MixedPropertyFetch>
<MoreSpecificImplementedParamType>
<code>$component</code>
</MoreSpecificImplementedParamType>
Expand All @@ -513,7 +483,6 @@
<code>DataType::parse($parser, $list)</code>
</PossiblyNullPropertyAssignmentValue>
<RedundantConditionGivenDocblockType>
<code>is_array($component)</code>
<code><![CDATA[isset($expr->name)]]></code>
</RedundantConditionGivenDocblockType>
</file>
Expand Down Expand Up @@ -1659,11 +1628,6 @@
<code>has</code>
</PossiblyNullReference>
</file>
<file src="tests/Parser/WithStatementTest.php">
<InvalidArgument>
<code>new stdClass()</code>
</InvalidArgument>
</file>
<file src="tests/TestCase.php">
<InvalidReturnStatement>
<code>$data</code>
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion src/Components/ParameterDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
4 changes: 0 additions & 4 deletions src/Components/WithKeyword.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
7 changes: 0 additions & 7 deletions tests/Parser/WithStatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use PhpMyAdmin\SqlParser\Lexer;
use PhpMyAdmin\SqlParser\Parser;
use PhpMyAdmin\SqlParser\Tests\TestCase;
use stdClass;

class WithStatementTest extends TestCase
{
Expand Down Expand Up @@ -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');
Expand Down