Skip to content
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
45 changes: 40 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
parameters:
ignoreErrors:
-
message: "#^Method PhpMyAdmin\\\\SqlParser\\\\Component\\:\\:__toString\\(\\) should return string but returns mixed\\.$#"
count: 1
path: src/Component.php

-
message: "#^Method PhpMyAdmin\\\\SqlParser\\\\Component\\:\\:build\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -105,6 +100,11 @@ parameters:
count: 1
path: src/Components/Array2d.php

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

-
message: "#^Method PhpMyAdmin\\\\SqlParser\\\\Components\\\\ArrayObj\\:\\:__construct\\(\\) has parameter \\$raw with no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -180,6 +180,11 @@ parameters:
count: 1
path: src/Components/Condition.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: "#^Parameter \\#1 \\$expr of class PhpMyAdmin\\\\SqlParser\\\\Components\\\\Condition constructor expects string\\|null, mixed given\\.$#"
count: 1
Expand Down Expand Up @@ -340,6 +345,11 @@ parameters:
count: 1
path: src/Components/ExpressionArray.php

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

-
message: "#^Parameter \\#1 \\$string of function strlen expects string, string\\|null given\\.$#"
count: 1
Expand Down Expand Up @@ -500,6 +510,11 @@ parameters:
count: 1
path: src/Components/JoinKeyword.php

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

-
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Components\\\\JoinKeyword\\:\\:\\$JOINS type has no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -690,6 +705,11 @@ parameters:
count: 1
path: src/Components/ParameterDefinition.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 Down Expand Up @@ -860,6 +880,21 @@ parameters:
count: 1
path: src/Components/UnionKeyword.php

-
message: "#^Method PhpMyAdmin\\\\SqlParser\\\\Components\\\\UnionKeyword\\:\\:parse\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#"
count: 1
path: src/Components/UnionKeyword.php

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

-
message: "#^Method PhpMyAdmin\\\\SqlParser\\\\Components\\\\WithKeyword\\:\\:parse\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#"
count: 1
path: src/Components/WithKeyword.php

-
message: "#^Method PhpMyAdmin\\\\SqlParser\\\\Context\\:\\:escape\\(\\) has parameter \\$str with no value type specified in iterable type array\\.$#"
count: 1
Expand Down
25 changes: 19 additions & 6 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.16.1@aa7e400908833b10c0333861f86cd48c510b60eb">
<file src="src/Component.php">
<MixedReturnStatement occurrences="1">
<code>static::build($this)</code>
</MixedReturnStatement>
</file>
<files psalm-version="4.17.0@6f4707aa41c9174353a6434bba3fc8840f981d9c">
<file src="src/Components/AlterOperation.php">
<DocblockTypeContradiction occurrences="1">
<code>$component-&gt;field !== ''</code>
Expand All @@ -31,6 +26,9 @@
</RedundantConditionGivenDocblockType>
</file>
<file src="src/Components/Array2d.php">
<InvalidArgument occurrences="1">
<code>$this</code>
</InvalidArgument>
<InvalidReturnStatement occurrences="1">
<code>$ret</code>
</InvalidReturnStatement>
Expand Down Expand Up @@ -103,6 +101,9 @@
</PossiblyInvalidOperand>
</file>
<file src="src/Components/Condition.php">
<InvalidArgument occurrences="1">
<code>$this</code>
</InvalidArgument>
<MixedArgument occurrences="1">
<code>$token-&gt;value</code>
</MixedArgument>
Expand Down Expand Up @@ -208,6 +209,9 @@
</RedundantConditionGivenDocblockType>
</file>
<file src="src/Components/ExpressionArray.php">
<InvalidArgument occurrences="1">
<code>$this</code>
</InvalidArgument>
<InvalidReturnStatement occurrences="1">
<code>$ret</code>
</InvalidReturnStatement>
Expand Down Expand Up @@ -300,6 +304,9 @@
<DocblockTypeContradiction occurrences="1">
<code>''</code>
</DocblockTypeContradiction>
<InvalidArgument occurrences="1">
<code>$this</code>
</InvalidArgument>
<MixedArrayOffset occurrences="4">
<code>static::$JOINS[$token-&gt;keyword]</code>
<code>static::$JOINS[$token-&gt;keyword]</code>
Expand Down Expand Up @@ -486,6 +493,9 @@
</PossiblyNullPropertyAssignmentValue>
</file>
<file src="src/Components/ParameterDefinition.php">
<InvalidArgument occurrences="1">
<code>$this</code>
</InvalidArgument>
<MixedArgument occurrences="1">
<code>$component-&gt;name</code>
</MixedArgument>
Expand Down Expand Up @@ -585,6 +595,9 @@
</RedundantCondition>
</file>
<file src="src/Components/UnionKeyword.php">
<InvalidArgument occurrences="1">
<code>$this</code>
</InvalidArgument>
<MoreSpecificImplementedParamType occurrences="1">
<code>$component</code>
</MoreSpecificImplementedParamType>
Expand Down
58 changes: 11 additions & 47 deletions src/Component.php
Original file line number Diff line number Diff line change
@@ -1,77 +1,41 @@
<?php
/**
* Defines a component that is later extended to parse specialized components or
* keywords.
*
* There is a small difference between *Component and *Keyword classes: usually,
* *Component parsers can be reused in multiple situations and *Keyword parsers
* count on the *Component classes to do their job.
*/

declare(strict_types=1);

namespace PhpMyAdmin\SqlParser;

use Exception;
use Stringable;

/**
* A component (of a statement) is a part of a statement that is common to
* multiple query types.
* A component (of a statement) is a part of a statement that is common to multiple query types.
*
* Defines a component that is later extended to parse specialized components or keywords.
*
* There is a small difference between *Component and *Keyword classes: usually, *Component parsers can be reused
* in multiple situations and *Keyword parsers count on the *Component classes to do their job.
*/
abstract class Component implements Stringable
interface Component extends Stringable
{
/**
* Parses the tokens contained in the given list in the context of the given
* parser.
* Parses the tokens contained in the given list in the context of the given parser.
*
* @param Parser $parser the parser that serves as context
* @param TokensList $list the list of tokens that are being parsed
* @param array $options parameters for parsing
*
* @return mixed
*
* @throws Exception not implemented yet.
*/
public static function parse(
Parser $parser,
TokensList $list,
array $options = []
) {
// This method should be abstract, but it can't be both static and
// abstract.
throw new Exception(Translator::gettext('Not implemented yet.'));
}
public static function parse(Parser $parser, TokensList $list, array $options = []);

/**
* Builds the string representation of a component of this type.
*
* In other words, this function represents the inverse function of
* `static::parse`.
* In other words, this function represents the inverse function of {@see Component::parse()}.
*
* @param mixed $component the component to be built
* @param array $options parameters for building
*
* @return mixed
*
* @throws Exception not implemented yet.
*/
public static function build($component, array $options = [])
{
// This method should be abstract, but it can't be both static and
// abstract.
throw new Exception(Translator::gettext('Not implemented yet.'));
}

/**
* Builds the string representation of a component of this type.
*
* @see static::build
*
* @return string
*/
public function __toString()
{
return static::build($this);
}
public static function build($component, array $options = []);
}
7 changes: 6 additions & 1 deletion src/Components/AlterOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
* @final
*/
class AlterOperation extends Component
class AlterOperation implements Component
{
/**
* All database options.
Expand Down Expand Up @@ -429,4 +429,9 @@ private static function checkIfTokenQuotedSymbol($token)
{
return $token->type === Token::TYPE_SYMBOL && $token->flags === Token::FLAG_SYMBOL_BACKTICK;
}

public function __toString(): string
{
return static::build($this);
}
}
7 changes: 6 additions & 1 deletion src/Components/Array2d.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
* @final
*/
class Array2d extends Component
class Array2d implements Component
{
/**
* @param Parser $parser the parser that serves as context
Expand Down Expand Up @@ -126,4 +126,9 @@ public static function build($component, array $options = [])
{
return ArrayObj::build($component);
}

public function __toString(): string
{
return static::build($this);
}
}
7 changes: 6 additions & 1 deletion src/Components/ArrayObj.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
* @final
*/
class ArrayObj extends Component
class ArrayObj implements Component
{
/**
* The array that contains the unprocessed value of each token.
Expand Down Expand Up @@ -181,4 +181,9 @@ public static function build($component, array $options = [])

return '(' . implode(', ', $component->values) . ')';
}

public function __toString(): string
{
return static::build($this);
}
}
7 changes: 6 additions & 1 deletion src/Components/CaseExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
* @final
*/
class CaseExpression extends Component
class CaseExpression implements Component
{
/**
* The value to be compared.
Expand Down Expand Up @@ -303,4 +303,9 @@ public static function build($component, array $options = [])

return $ret;
}

public function __toString(): string
{
return static::build($this);
}
}
7 changes: 6 additions & 1 deletion src/Components/Condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
* @final
*/
class Condition extends Component
class Condition implements Component
{
/**
* Logical operators that can be used to delimit expressions.
Expand Down Expand Up @@ -239,4 +239,9 @@ public static function build($component, array $options = [])

return $component->expr;
}

public function __toString(): string
{
return static::build($this);
}
}
7 changes: 6 additions & 1 deletion src/Components/CreateDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*
* @final
*/
class CreateDefinition extends Component
class CreateDefinition implements Component
{
/**
* All field options.
Expand Down Expand Up @@ -358,4 +358,9 @@ public static function build($component, array $options = [])

return trim($tmp);
}

public function __toString(): string
{
return static::build($this);
}
}
7 changes: 6 additions & 1 deletion src/Components/DataType.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
* @final
*/
class DataType extends Component
class DataType implements Component
{
/**
* All data type options.
Expand Down Expand Up @@ -174,4 +174,9 @@ public static function build($component, array $options = [])

return trim($name . $parameters . ' ' . $component->options);
}

public function __toString(): string
{
return static::build($this);
}
}
Loading