Skip to content

Commit f24633d

Browse files
Merge pull request #481 from kamil-tekiela/Fix-build-param-types
Fix build method param types
2 parents 577b1cc + bb7a7f6 commit f24633d

File tree

6 files changed

+4
-76
lines changed

6 files changed

+4
-76
lines changed

phpstan-baseline.neon

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,6 @@ parameters:
7575
count: 2
7676
path: src/Components/CaseExpression.php
7777

78-
-
79-
message: "#^Parameter \\#1 \\$component of static method PhpMyAdmin\\\\SqlParser\\\\Components\\\\Condition\\:\\:build\\(\\) expects array\\<PhpMyAdmin\\\\SqlParser\\\\Components\\\\Condition\\>, \\$this\\(PhpMyAdmin\\\\SqlParser\\\\Components\\\\Condition\\) given\\.$#"
80-
count: 1
81-
path: src/Components/Condition.php
82-
83-
-
84-
message: "#^Unreachable statement \\- code above always terminates\\.$#"
85-
count: 1
86-
path: src/Components/Condition.php
87-
8878
-
8979
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Components\\\\CreateDefinition\\:\\:\\$name \\(string\\|null\\) does not accept mixed\\.$#"
9080
count: 2
@@ -330,11 +320,6 @@ parameters:
330320
count: 2
331321
path: src/Components/OrderKeyword.php
332322

333-
-
334-
message: "#^Parameter \\#1 \\$component of static method PhpMyAdmin\\\\SqlParser\\\\Components\\\\ParameterDefinition\\:\\:build\\(\\) expects array\\<PhpMyAdmin\\\\SqlParser\\\\Components\\\\ParameterDefinition\\>, \\$this\\(PhpMyAdmin\\\\SqlParser\\\\Components\\\\ParameterDefinition\\) given\\.$#"
335-
count: 1
336-
path: src/Components/ParameterDefinition.php
337-
338323
-
339324
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Components\\\\ParameterDefinition\\:\\:\\$inOut \\(string\\) does not accept string\\|null\\.$#"
340325
count: 1
@@ -360,11 +345,6 @@ parameters:
360345
count: 2
361346
path: src/Components/ParameterDefinition.php
362347

363-
-
364-
message: "#^Unreachable statement \\- code above always terminates\\.$#"
365-
count: 1
366-
path: src/Components/ParameterDefinition.php
367-
368348
-
369349
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Components\\\\PartitionDefinition\\:\\:\\$expr \\(PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|string\\) does not accept PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\|null\\.$#"
370350
count: 1
@@ -586,7 +566,7 @@ parameters:
586566
path: src/Statements/CreateStatement.php
587567

588568
-
589-
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\\.$#"
569+
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\\.$#"
590570
count: 1
591571
path: src/Statements/CreateStatement.php
592572

@@ -946,7 +926,7 @@ parameters:
946926
path: tests/Builder/CreateStatementTest.php
947927

948928
-
949-
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\\.$#"
929+
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\\.$#"
950930
count: 2
951931
path: tests/Builder/CreateStatementTest.php
952932

@@ -1055,11 +1035,6 @@ parameters:
10551035
count: 1
10561036
path: tests/Parser/SelectStatementTest.php
10571037

1058-
-
1059-
message: "#^Parameter \\#1 \\$component of static method PhpMyAdmin\\\\SqlParser\\\\Components\\\\WithKeyword\\:\\:build\\(\\) expects PhpMyAdmin\\\\SqlParser\\\\Components\\\\WithKeyword, stdClass given\\.$#"
1060-
count: 1
1061-
path: tests/Parser/WithStatementTest.php
1062-
10631038
-
10641039
message: "#^Parameter \\#2 \\$list of static method PhpMyAdmin\\\\SqlParser\\\\Utils\\\\Query\\:\\:getClause\\(\\) expects PhpMyAdmin\\\\SqlParser\\\\TokensList, PhpMyAdmin\\\\SqlParser\\\\TokensList\\|null given\\.$#"
10651040
count: 9

psalm-baseline.xml

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -128,30 +128,15 @@
128128
</MoreSpecificImplementedParamType>
129129
</file>
130130
<file src="src/Components/Condition.php">
131-
<InvalidArgument>
132-
<code>$this</code>
133-
</InvalidArgument>
134131
<MixedArrayOffset>
135132
<code><![CDATA[static::$allowedKeywords[$token->value]]]></code>
136133
</MixedArrayOffset>
137-
<MixedInferredReturnType>
138-
<code>string</code>
139-
</MixedInferredReturnType>
140-
<MixedPropertyFetch>
141-
<code><![CDATA[$component->expr]]></code>
142-
</MixedPropertyFetch>
143-
<MixedReturnStatement>
144-
<code><![CDATA[$component->expr]]></code>
145-
</MixedReturnStatement>
146134
<MoreSpecificImplementedParamType>
147135
<code>$component</code>
148136
</MoreSpecificImplementedParamType>
149137
<PossiblyUnusedProperty>
150138
<code>$isOperator</code>
151139
</PossiblyUnusedProperty>
152-
<RedundantConditionGivenDocblockType>
153-
<code>is_array($component)</code>
154-
</RedundantConditionGivenDocblockType>
155140
</file>
156141
<file src="src/Components/CreateDefinition.php">
157142
<MixedAssignment>
@@ -479,24 +464,9 @@
479464
</PossiblyNullPropertyAssignmentValue>
480465
</file>
481466
<file src="src/Components/ParameterDefinition.php">
482-
<InvalidArgument>
483-
<code>$this</code>
484-
</InvalidArgument>
485-
<MixedArgument>
486-
<code><![CDATA[$component->name]]></code>
487-
</MixedArgument>
488467
<MixedAssignment>
489468
<code><![CDATA[$expr->name]]></code>
490469
</MixedAssignment>
491-
<MixedOperand>
492-
<code><![CDATA[$component->inOut]]></code>
493-
<code><![CDATA[$component->type]]></code>
494-
</MixedOperand>
495-
<MixedPropertyFetch>
496-
<code><![CDATA[$component->inOut]]></code>
497-
<code><![CDATA[$component->name]]></code>
498-
<code><![CDATA[$component->type]]></code>
499-
</MixedPropertyFetch>
500470
<MoreSpecificImplementedParamType>
501471
<code>$component</code>
502472
</MoreSpecificImplementedParamType>
@@ -507,7 +477,6 @@
507477
<code>DataType::parse($parser, $list)</code>
508478
</PossiblyNullPropertyAssignmentValue>
509479
<RedundantConditionGivenDocblockType>
510-
<code>is_array($component)</code>
511480
<code><![CDATA[isset($expr->name)]]></code>
512481
</RedundantConditionGivenDocblockType>
513482
</file>
@@ -1644,11 +1613,6 @@
16441613
<code>has</code>
16451614
</PossiblyNullReference>
16461615
</file>
1647-
<file src="tests/Parser/WithStatementTest.php">
1648-
<InvalidArgument>
1649-
<code>new stdClass()</code>
1650-
</InvalidArgument>
1651-
</file>
16521616
<file src="tests/TestCase.php">
16531617
<InvalidReturnStatement>
16541618
<code>$data</code>

src/Components/Condition.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
221221
}
222222

223223
/**
224-
* @param Condition[] $component the component to be built
224+
* @param Condition[]|Condition $component the component to be built
225225
*/
226226
public static function build($component): string
227227
{

src/Components/ParameterDefinition.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
141141
}
142142

143143
/**
144-
* @param ParameterDefinition[] $component the component to be built
144+
* @param ParameterDefinition[]|ParameterDefinition $component the component to be built
145145
*/
146146
public static function build($component): string
147147
{

src/Components/WithKeyword.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ public static function parse(Parser $parser, TokensList $list, array $options =
5050
*/
5151
public static function build($component): string
5252
{
53-
if (! $component instanceof WithKeyword) {
54-
throw new RuntimeException('Can not build a component that is not a WithKeyword');
55-
}
56-
5753
if (! isset($component->statement)) {
5854
throw new RuntimeException('No statement inside WITH');
5955
}

tests/Parser/WithStatementTest.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use PhpMyAdmin\SqlParser\Lexer;
99
use PhpMyAdmin\SqlParser\Parser;
1010
use PhpMyAdmin\SqlParser\Tests\TestCase;
11-
use stdClass;
1211

1312
class WithStatementTest extends TestCase
1413
{
@@ -134,12 +133,6 @@ public function testWithHasUnclosedParenthesis(): void
134133
$this->assertEquals($parserErrors[0][0], 'A closing bracket was expected.');
135134
}
136135

137-
public function testBuildWrongWithKeyword(): void
138-
{
139-
$this->expectExceptionMessage('Can not build a component that is not a WithKeyword');
140-
WithKeyword::build(new stdClass());
141-
}
142-
143136
public function testBuildBadWithKeyword(): void
144137
{
145138
$this->expectExceptionMessage('No statement inside WITH');

0 commit comments

Comments
 (0)