Skip to content

Commit

Permalink
Merge pull request #481 from kamil-tekiela/Fix-build-param-types
Browse files Browse the repository at this point in the history
Fix build method param types
  • Loading branch information
MauricioFauth committed Jul 26, 2023
2 parents 577b1cc + bb7a7f6 commit f24633d
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 76 deletions.
29 changes: 2 additions & 27 deletions phpstan-baseline.neon
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 @@ -330,11 +320,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 @@ -360,11 +345,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 @@ -586,7 +566,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 @@ -946,7 +926,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 @@ -1055,11 +1035,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
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 @@ -479,24 +464,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 @@ -507,7 +477,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 @@ -1644,11 +1613,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
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
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
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
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

0 comments on commit f24633d

Please sign in to comment.