Skip to content

Commit

Permalink
Merge pull request #521 from kamil-tekiela/param-types-3
Browse files Browse the repository at this point in the history
Add native param types
  • Loading branch information
MauricioFauth authored Jan 15, 2024
2 parents 25a0713 + b475467 commit fe490db
Show file tree
Hide file tree
Showing 39 changed files with 122 additions and 137 deletions.
36 changes: 0 additions & 36 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -646,15 +646,6 @@
<code><![CDATA[self::STATEMENT_PARSERS[$statementName ?? $token->keyword]]]></code>
<code><![CDATA[self::STATEMENT_PARSERS[$token->keyword]]]></code>
</MixedArrayOffset>
<PossiblyNullArgument>
<code>$list</code>
<code>$list</code>
<code>$list</code>
<code><![CDATA[$token->token]]></code>
</PossiblyNullArgument>
<PossiblyNullArrayAccess>
<code><![CDATA[$list->tokens[$list->idx]]]></code>
</PossiblyNullArrayAccess>
<PossiblyNullArrayOffset>
<code><![CDATA[$list->tokens]]></code>
<code>self::STATEMENT_PARSERS</code>
Expand All @@ -664,27 +655,9 @@
<code><![CDATA[$list->idx]]></code>
<code>$prevLastIdx</code>
</PossiblyNullOperand>
<PossiblyNullPropertyAssignment>
<code>$list</code>
<code>$list</code>
</PossiblyNullPropertyAssignment>
<PossiblyNullPropertyAssignmentValue>
<code>$lastIdx</code>
</PossiblyNullPropertyAssignmentValue>
<PossiblyNullPropertyFetch>
<code><![CDATA[$list->count]]></code>
<code><![CDATA[$list->idx]]></code>
<code><![CDATA[$list->tokens]]></code>
<code><![CDATA[$token->keyword]]></code>
<code><![CDATA[$token->token]]></code>
<code><![CDATA[$token->type]]></code>
<code><![CDATA[$token->value]]></code>
</PossiblyNullPropertyFetch>
<PossiblyNullReference>
<code>getNextOfType</code>
<code>getNextOfType</code>
<code>getNextOfType</code>
</PossiblyNullReference>
<UnsupportedPropertyReferenceUsage>
<code><![CDATA[$list = &$this->list]]></code>
</UnsupportedPropertyReferenceUsage>
Expand Down Expand Up @@ -1053,8 +1026,6 @@
<code>$idx</code>
</MixedArgumentTypeCoercion>
<PossiblyFalseArgument>
<code>$params</code>
<code>$params</code>
<code><![CDATA[$params['c']]]></code>
<code><![CDATA[$params['q']]]></code>
<code><![CDATA[$params['q']]]></code>
Expand Down Expand Up @@ -1542,13 +1513,6 @@
<code><![CDATA[$parser->list]]></code>
<code><![CDATA[$parser->list]]></code>
<code><![CDATA[$parser->list]]></code>
<code><![CDATA[$parser->list]]></code>
<code><![CDATA[$parser->list]]></code>
<code><![CDATA[$parser->list]]></code>
<code><![CDATA[$parser->list]]></code>
<code><![CDATA[$parser->list]]></code>
<code><![CDATA[$parser->list]]></code>
<code><![CDATA[$parser->list]]></code>
</PossiblyNullArgument>
<PossiblyUnusedMethod>
<code>getFlagsProvider</code>
Expand Down
10 changes: 5 additions & 5 deletions src/Components/AlterOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,9 @@ final class AlterOperation implements Component
* @param Token[] $unknown unparsed tokens found at the end of operation
*/
public function __construct(
$options = null,
$field = null,
$partitions = null,
OptionsArray|null $options = null,
Expression|string|null $field = null,
array|null $partitions = null,
public array $unknown = []
) {
$this->partitions = $partitions;
Expand Down Expand Up @@ -527,7 +527,7 @@ public function build(): string
*
* @param string $tokenValue Value of current token
*/
private static function checkIfColumnDefinitionKeyword($tokenValue): bool
private static function checkIfColumnDefinitionKeyword(string $tokenValue): bool
{
$commonOptions = [
'AUTO_INCREMENT',
Expand All @@ -551,7 +551,7 @@ private static function checkIfColumnDefinitionKeyword($tokenValue): bool
*
* @param Token $token token to check
*/
private static function checkIfTokenQuotedSymbol($token): bool
private static function checkIfTokenQuotedSymbol(Token $token): bool
{
return $token->type === TokenType::Symbol && $token->flags === Token::FLAG_SYMBOL_BACKTICK;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ final class Condition implements Component
/**
* @param string $expr the condition or the operator
*/
public function __construct($expr = null)
public function __construct(string|null $expr = null)
{
$this->expr = trim((string) $expr);
}
Expand Down
10 changes: 5 additions & 5 deletions src/Components/CreateDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,11 @@ final class CreateDefinition implements Component
* @param Reference|null $references references
*/
public function __construct(
$name = null,
$options = null,
$type = null,
$isConstraint = false,
$references = null
string|null $name = null,
OptionsArray|null $options = null,
DataType|Key|null $type = null,
bool $isConstraint = false,
Reference|null $references = null
) {
$this->name = $name;
$this->options = $options;
Expand Down
4 changes: 2 additions & 2 deletions src/Components/DataType.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ final class DataType implements Component
* @param OptionsArray $options the options of this data type
*/
public function __construct(
$name = null,
string|null $name = null,
array $parameters = [],
$options = null
OptionsArray|null $options = null
) {
$this->name = $name;
$this->parameters = $parameters;
Expand Down
8 changes: 6 additions & 2 deletions src/Components/Expression.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,12 @@ final class Expression implements Component
* @param string|null $column the name of the column
* @param string|null $alias the name of the alias
*/
public function __construct($database = null, $table = null, $column = null, $alias = null)
{
public function __construct(
string|null $database = null,
string|null $table = null,
string|null $column = null,
string|null $alias = null
) {
if (($column === null) && ($alias === null)) {
$this->expr = $database; // case 1
$this->alias = $table; // case 2
Expand Down
2 changes: 1 addition & 1 deletion src/Components/FunctionCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ final class FunctionCall implements Component
* @param string|null $name the name of the function to be called
* @param string[]|ArrayObj|null $parameters the parameters of this function
*/
public function __construct($name = null, $parameters = null)
public function __construct(string|null $name = null, array|ArrayObj|null $parameters = null)
{
$this->name = $name;
if (is_array($parameters)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Components/GroupKeyword.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ final class GroupKeyword implements Component
/**
* @param Expression $expr the expression that we are sorting by
*/
public function __construct($expr = null)
public function __construct(Expression|null $expr = null)
{
$this->expr = $expr;
}
Expand Down
14 changes: 7 additions & 7 deletions src/Components/IntoKeyword.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ final class IntoKeyword implements Component
* @param bool|null $fieldsKeyword options for OPTIONS keyword
*/
public function __construct(
$type = null,
$dest = null,
$columns = null,
$values = null,
$fieldsOptions = null,
$fieldsKeyword = null
string|null $type = null,
string|Expression|null $dest = null,
array|null $columns = null,
array|null $values = null,
OptionsArray|null $fieldsOptions = null,
bool|null $fieldsKeyword = null
) {
$this->type = $type;
$this->dest = $dest;
Expand Down Expand Up @@ -236,7 +236,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
* @param TokensList $list A token list
* @param string $keyword The keyword
*/
public function parseFileOptions(Parser $parser, TokensList $list, $keyword = 'FIELDS'): void
public function parseFileOptions(Parser $parser, TokensList $list, string $keyword = 'FIELDS'): void
{
++$list->idx;

Expand Down
8 changes: 6 additions & 2 deletions src/Components/JoinKeyword.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,12 @@ final class JoinKeyword implements Component
* @param Condition[] $on join conditions
* @param ArrayObj $using columns joined
*/
public function __construct($type = null, $expr = null, $on = null, $using = null)
{
public function __construct(
string|null $type = null,
Expression|null $expr = null,
array|null $on = null,
ArrayObj|null $using = null
) {
$this->type = $type;
$this->expr = $expr;
$this->on = $on;
Expand Down
6 changes: 3 additions & 3 deletions src/Components/Key.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ final class Key implements Component
* @phpstan-param array{name?: string, length?: int, order?: string}[] $columns
*/
public function __construct(
$name = null,
string|null $name = null,
array $columns = [],
$type = null,
$options = null
string|null $type = null,
OptionsArray|null $options = null
) {
$this->name = $name;
$this->columns = $columns;
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Limit.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ final class Limit implements Component
* @param int|string $rowCount the row count
* @param int|string $offset the offset
*/
public function __construct($rowCount = 0, $offset = 0)
public function __construct(int|string $rowCount = 0, int|string $offset = 0)
{
$this->rowCount = $rowCount;
$this->offset = $offset;
Expand Down
4 changes: 2 additions & 2 deletions src/Components/OptionsArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ public function build(): string
* @param bool $getExpr Gets the expression instead of the value.
* The value is the processed form of the expression.
*/
public function has($key, $getExpr = false): mixed
public function has(string $key, bool $getExpr = false): mixed
{
foreach ($this->options as $option) {
if (is_array($option)) {
Expand All @@ -313,7 +313,7 @@ public function has($key, $getExpr = false): mixed
*
* @return bool whether the key was found and deleted or not
*/
public function remove($key): bool
public function remove(string $key): bool
{
foreach ($this->options as $idx => $option) {
if (is_array($option)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Components/OrderKeyword.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ final class OrderKeyword implements Component
* @param Expression $expr the expression that we are sorting by
* @param string $type the sorting type
*/
public function __construct($expr = null, $type = 'ASC')
public function __construct(Expression|null $expr = null, string $type = 'ASC')
{
$this->expr = $expr;
$this->type = $type;
Expand Down
2 changes: 1 addition & 1 deletion src/Components/ParameterDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ final class ParameterDefinition implements Component
* @param string $inOut parameter's directional type (IN / OUT or None)
* @param DataType $type parameter's type
*/
public function __construct($name = null, $inOut = null, $type = null)
public function __construct(string|null $name = null, string|null $inOut = null, DataType|null $type = null)
{
$this->name = $name;
$this->inOut = $inOut;
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Reference.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ final class Reference implements Component
* @param string[] $columns the columns referenced
* @param OptionsArray $options the options
*/
public function __construct($table = null, array $columns = [], $options = null)
public function __construct(Expression|null $table = null, array $columns = [], OptionsArray|null $options = null)
{
$this->table = $table;
$this->columns = $columns;
Expand Down
2 changes: 1 addition & 1 deletion src/Components/RenameOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ final class RenameOperation implements Component
* @param Expression $old old expression
* @param Expression $new new expression containing new name
*/
public function __construct($old = null, $new = null)
public function __construct(Expression|null $old = null, Expression|null $new = null)
{
$this->old = $old;
$this->new = $new;
Expand Down
2 changes: 1 addition & 1 deletion src/Components/SetOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ final class SetOperation implements Component
* @param string $column Field's name..
* @param string $value new value
*/
public function __construct($column = '', $value = '')
public function __construct(string $column = '', string $value = '')
{
$this->column = $column;
$this->value = $value;
Expand Down
4 changes: 1 addition & 3 deletions src/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -604,10 +604,8 @@ public static function getMode(): int

/**
* Sets the SQL mode.
*
* @param int|string $mode
*/
public static function setMode($mode = self::SQL_MODE_NONE): void
public static function setMode(int|string $mode = self::SQL_MODE_NONE): void
{
if (is_int($mode)) {
static::$mode = $mode;
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/LexerException.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class LexerException extends Exception
* @param int $pos the position of the character
* @param int $code the code of this error
*/
public function __construct($msg = '', $ch = '', $pos = 0, $code = 0)
public function __construct(string $msg = '', string $ch = '', int $pos = 0, int $code = 0)
{
parent::__construct($msg, $code);
$this->ch = $ch;
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/ParserException.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ParserException extends Exception
* @param Token $token the token that produced this exception
* @param int $code the code of this error
*/
public function __construct($msg = '', Token|null $token = null, $code = 0)
public function __construct(string $msg = '', Token|null $token = null, int $code = 0)
{
parent::__construct($msg, $code);
$this->token = $token;
Expand Down
8 changes: 4 additions & 4 deletions src/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class Lexer
* enabled or not
* @param string $delimiter the delimiter to be used
*/
public function __construct($str, $strict = false, $delimiter = null)
public function __construct(string|UtfString $str, bool $strict = false, string|null $delimiter = null)
{
if (Context::$keywords === []) {
Context::load();
Expand Down Expand Up @@ -158,7 +158,7 @@ public function __construct($str, $strict = false, $delimiter = null)
*
* @param string $delimiter the new delimiter
*/
public function setDelimiter($delimiter): void
public function setDelimiter(string $delimiter): void
{
$this->delimiter = $delimiter;
$this->delimiterLen = strlen($delimiter);
Expand Down Expand Up @@ -383,7 +383,7 @@ private function solveAmbiguityOnFunctionKeywords(): void
*
* @throws LexerException throws the exception, if strict mode is enabled.
*/
public function error($msg, $str = '', $pos = 0, $code = 0): void
public function error(string $msg, string $str = '', int $pos = 0, int $code = 0): void
{
$error = new LexerException(
Translator::gettext($msg),
Expand Down Expand Up @@ -873,7 +873,7 @@ public function parseNumber(): Token|null
*
* @throws LexerException
*/
public function parseString($quote = ''): Token|null
public function parseString(string $quote = ''): Token|null
{
$token = $this->str[$this->last];
$flags = Context::isString($token);
Expand Down
4 changes: 2 additions & 2 deletions src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ class Parser
* @param string|UtfString|TokensList|null $list the list of tokens to be parsed
* @param bool $strict whether strict mode should be enabled or not
*/
public function __construct($list = null, $strict = false)
public function __construct(string|UtfString|TokensList|null $list = null, bool $strict = false)
{
if (Context::$keywords === []) {
Context::load();
Expand Down Expand Up @@ -634,7 +634,7 @@ public function parse(): void
*
* @throws ParserException throws the exception, if strict mode is enabled.
*/
public function error($msg, Token|null $token = null, $code = 0): void
public function error(string $msg, Token|null $token = null, int $code = 0): void
{
$error = new ParserException(
Translator::gettext($msg),
Expand Down
2 changes: 1 addition & 1 deletion src/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ public function __toString(): string
*
* @throws Exceptions\ParserException
*/
public function validateClauseOrder($parser, $list): bool
public function validateClauseOrder(Parser $parser, TokensList $list): bool
{
$clauses = array_flip(array_keys($this->getClauses()));

Expand Down
Loading

0 comments on commit fe490db

Please sign in to comment.