Skip to content

Commit

Permalink
Fix invalid types
Browse files Browse the repository at this point in the history
Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
  • Loading branch information
kamil-tekiela committed Aug 17, 2023
1 parent 5cb99fc commit 2930a89
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 61 deletions.
25 changes: 0 additions & 25 deletions phpstan-baseline.neon
Expand Up @@ -25,16 +25,6 @@ parameters:
count: 3
path: src/Components/AlterOperation.php

-
message: "#^Cannot access property \\$values on array\\<PhpMyAdmin\\\\SqlParser\\\\Component\\>\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\ArrayObj\\.$#"
count: 1
path: src/Components/Array2d.php

-
message: "#^Method PhpMyAdmin\\\\SqlParser\\\\Components\\\\Array2d\\:\\:parse\\(\\) should return array\\<PhpMyAdmin\\\\SqlParser\\\\Components\\\\ArrayObj\\> but returns array\\<int\\<0, max\\>, array\\<PhpMyAdmin\\\\SqlParser\\\\Component\\>\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\ArrayObj\\>\\.$#"
count: 1
path: src/Components/Array2d.php

-
message: "#^Cannot access an offset on array\\<int\\<0, max\\>, mixed\\>\\|static\\(PhpMyAdmin\\\\SqlParser\\\\Components\\\\ArrayObj\\)\\.$#"
count: 1
Expand Down Expand Up @@ -580,11 +570,6 @@ parameters:
count: 1
path: src/Statements/DeleteStatement.php

-
message: "#^Parameter \\#1 \\$component of static method PhpMyAdmin\\\\SqlParser\\\\Components\\\\ExpressionArray\\:\\:buildAll\\(\\) expects array\\<PhpMyAdmin\\\\SqlParser\\\\Components\\\\Expression\\>, array\\<PhpMyAdmin\\\\SqlParser\\\\Components\\\\OrderKeyword\\> given\\.$#"
count: 1
path: src/Statements/DeleteStatement.php

-
message: "#^Parameter \\#1 \\$component of static method PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\:\\:build\\(\\) expects PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray, PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null given\\.$#"
count: 1
Expand Down Expand Up @@ -675,16 +660,6 @@ parameters:
count: 1
path: src/Statements/RenameStatement.php

-
message: "#^Parameter \\#1 \\$component of static method PhpMyAdmin\\\\SqlParser\\\\Components\\\\Array2d\\:\\:buildAll\\(\\) expects array\\<PhpMyAdmin\\\\SqlParser\\\\Components\\\\ArrayObj\\>, array\\<PhpMyAdmin\\\\SqlParser\\\\Components\\\\Array2d\\> given\\.$#"
count: 1
path: src/Statements/ReplaceStatement.php

-
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Statements\\\\ReplaceStatement\\:\\:\\$values \\(array\\<PhpMyAdmin\\\\SqlParser\\\\Components\\\\Array2d\\>\\|null\\) does not accept array\\<PhpMyAdmin\\\\SqlParser\\\\Components\\\\ArrayObj\\>\\.$#"
count: 1
path: src/Statements/ReplaceStatement.php

-
message: "#^Parameter \\#1 \\$component of static method PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\:\\:build\\(\\) expects PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray, PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null given\\.$#"
count: 2
Expand Down
21 changes: 3 additions & 18 deletions psalm-baseline.xml
Expand Up @@ -59,18 +59,9 @@
</PropertyTypeCoercion>
</file>
<file src="src/Components/Array2d.php">
<InvalidReturnStatement>
<code>$ret</code>
</InvalidReturnStatement>
<InvalidReturnType>
<code>ArrayObj[]</code>
</InvalidReturnType>
<MoreSpecificImplementedParamType>
<code>$component</code>
</MoreSpecificImplementedParamType>
<PossiblyInvalidPropertyFetch>
<code><![CDATA[$arr->values]]></code>
</PossiblyInvalidPropertyFetch>
</file>
<file src="src/Components/ArrayObj.php">
<MixedAssignment>
Expand Down Expand Up @@ -221,6 +212,9 @@
<code>$expr</code>
<code>$expr</code>
</PossiblyNullArgument>
<PossiblyUnusedMethod>
<code>buildAll</code>
</PossiblyUnusedMethod>
</file>
<file src="src/Components/FunctionCall.php">
<MixedOperand>
Expand Down Expand Up @@ -988,9 +982,6 @@
</RedundantConditionGivenDocblockType>
</file>
<file src="src/Statements/DeleteStatement.php">
<InvalidArgument>
<code><![CDATA[$this->order]]></code>
</InvalidArgument>
<MixedArgument>
<code><![CDATA[$token->keyword]]></code>
</MixedArgument>
Expand Down Expand Up @@ -1098,12 +1089,6 @@
</PossiblyNullArgument>
</file>
<file src="src/Statements/ReplaceStatement.php">
<InvalidArgument>
<code><![CDATA[$this->values]]></code>
</InvalidArgument>
<InvalidPropertyAssignmentValue>
<code>Array2d::parse($parser, $list)</code>
</InvalidPropertyAssignmentValue>
<PossiblyNullOperand>
<code><![CDATA[$this->into]]></code>
<code><![CDATA[$this->options]]></code>
Expand Down
9 changes: 1 addition & 8 deletions src/Components/Array2d.php
Expand Up @@ -77,6 +77,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
break;
}

/** @var ArrayObj $arr */
$arr = ArrayObj::parse($parser, $list, $options);
$arrCount = count($arr->values);
if ($count === -1) {
Expand Down Expand Up @@ -120,14 +121,6 @@ public static function build($component): string
throw new RuntimeException(Translator::gettext('Not implemented yet.'));

Check warning on line 121 in src/Components/Array2d.php

View check run for this annotation

Codecov / codecov/patch

src/Components/Array2d.php#L121

Added line #L121 was not covered by tests
}

/**
* @param ArrayObj[] $component the component to be built
*/
public static function buildAll(array $component): string
{
return ArrayObj::buildAll($component);
}

public function __toString(): string
{
return static::build($this);
Expand Down
2 changes: 1 addition & 1 deletion src/Components/IndexHint.php
Expand Up @@ -186,7 +186,7 @@ public static function build($component): string
$ret .= 'FOR ' . $component->for . ' ';
}

return $ret . ExpressionArray::buildAll($component->indexes);
return $ret . Expression::buildAll($component->indexes);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Components/IntoKeyword.php
Expand Up @@ -270,7 +270,7 @@ public static function build($component): string
}

if (isset($component->values)) {
return ExpressionArray::buildAll($component->values);
return Expression::buildAll($component->values);
}

$ret = 'OUTFILE "' . $component->dest . '"';
Expand Down
8 changes: 4 additions & 4 deletions src/Statements/DeleteStatement.php
Expand Up @@ -165,27 +165,27 @@ public function build()
$ret = 'DELETE ' . OptionsArray::build($this->options);

if ($this->columns !== null && $this->columns !== []) {
$ret .= ' ' . ExpressionArray::buildAll($this->columns);
$ret .= ' ' . Expression::buildAll($this->columns);
}

if ($this->from !== null && $this->from !== []) {
$ret .= ' FROM ' . ExpressionArray::buildAll($this->from);
$ret .= ' FROM ' . Expression::buildAll($this->from);
}

if ($this->join !== null && $this->join !== []) {
$ret .= ' ' . JoinKeyword::buildAll($this->join);
}

if ($this->using !== null && $this->using !== []) {
$ret .= ' USING ' . ExpressionArray::buildAll($this->using);
$ret .= ' USING ' . Expression::buildAll($this->using);
}

if ($this->where !== null && $this->where !== []) {
$ret .= ' WHERE ' . Condition::buildAll($this->where);
}

if ($this->order !== null && $this->order !== []) {
$ret .= ' ORDER BY ' . ExpressionArray::buildAll($this->order);
$ret .= ' ORDER BY ' . OrderKeyword::buildAll($this->order);
}

if ($this->limit !== null && strlen((string) $this->limit) > 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/Statements/LoadStatement.php
Expand Up @@ -214,7 +214,7 @@ public function build()
}

if ($this->columnNamesOrUserVariables !== null && $this->columnNamesOrUserVariables !== []) {
$ret .= ' ' . ExpressionArray::buildAll($this->columnNamesOrUserVariables);
$ret .= ' ' . Expression::buildAll($this->columnNamesOrUserVariables);
}

if ($this->set !== null && $this->set !== []) {
Expand Down
5 changes: 3 additions & 2 deletions src/Statements/ReplaceStatement.php
Expand Up @@ -5,6 +5,7 @@
namespace PhpMyAdmin\SqlParser\Statements;

use PhpMyAdmin\SqlParser\Components\Array2d;
use PhpMyAdmin\SqlParser\Components\ArrayObj;
use PhpMyAdmin\SqlParser\Components\IntoKeyword;
use PhpMyAdmin\SqlParser\Components\OptionsArray;
use PhpMyAdmin\SqlParser\Components\SetOperation;
Expand Down Expand Up @@ -60,7 +61,7 @@ class ReplaceStatement extends Statement
/**
* Values to be replaced.
*
* @var Array2d[]|null
* @var ArrayObj[]|null
*/
public array|null $values = null;

Expand Down Expand Up @@ -89,7 +90,7 @@ public function build()
$ret = trim($ret) . ' INTO ' . $this->into;

if ($this->values !== null && $this->values !== []) {
$ret .= ' VALUES ' . Array2d::buildAll($this->values);
$ret .= ' VALUES ' . ArrayObj::buildAll($this->values);
} elseif ($this->set !== null && $this->set !== []) {
$ret .= ' SET ' . SetOperation::buildAll($this->set);
} elseif ($this->select !== null && strlen((string) $this->select) > 0) {
Expand Down
3 changes: 2 additions & 1 deletion tests/Components/Array2dTest.php
Expand Up @@ -5,6 +5,7 @@
namespace PhpMyAdmin\SqlParser\Tests\Components;

use PhpMyAdmin\SqlParser\Components\Array2d;
use PhpMyAdmin\SqlParser\Components\ArrayObj;
use PhpMyAdmin\SqlParser\Parser;
use PhpMyAdmin\SqlParser\Tests\TestCase;

Expand All @@ -28,7 +29,7 @@ public function testBuildAll(): void
$arrays = Array2d::parse(new Parser(), $this->getTokensList('(1, 2), (3, 4), (5, 6)'));
$this->assertEquals(
'(1, 2), (3, 4), (5, 6)',
Array2d::buildAll($arrays)
ArrayObj::buildAll($arrays)
);
}

Expand Down

0 comments on commit 2930a89

Please sign in to comment.