diff --git a/phpcs.xml.dist b/phpcs.xml.dist index e19cce16d..07e829c2d 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -66,9 +66,6 @@ 4 - - 4 - 4 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index e442ecfe0..b2755a74b 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -857,9 +857,6 @@ $built[$field] value]]]> - - __toString - value]]]> value]]]> @@ -1206,9 +1203,6 @@ - - __toString - $byteLen diff --git a/src/Component.php b/src/Component.php index 9ee99a884..d3df767a5 100644 --- a/src/Component.php +++ b/src/Component.php @@ -22,10 +22,8 @@ interface Component extends Stringable * @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 */ - public static function parse(Parser $parser, TokensList $list, array $options = []); + public static function parse(Parser $parser, TokensList $list, array $options = []): mixed; /** * Builds the string representation of a component of this type. diff --git a/src/Components/AlterOperation.php b/src/Components/AlterOperation.php index 569704960..d688e05da 100644 --- a/src/Components/AlterOperation.php +++ b/src/Components/AlterOperation.php @@ -300,10 +300,8 @@ public function __construct( * @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 AlterOperation */ - public static function parse(Parser $parser, TokensList $list, array $options = []) + public static function parse(Parser $parser, TokensList $list, array $options = []): AlterOperation { $ret = new static(); diff --git a/src/Components/ArrayObj.php b/src/Components/ArrayObj.php index 679a60055..75a5ee8a2 100644 --- a/src/Components/ArrayObj.php +++ b/src/Components/ArrayObj.php @@ -49,7 +49,7 @@ public function __construct(array $raw = [], array $values = []) * * @return ArrayObj|Component[] */ - public static function parse(Parser $parser, TokensList $list, array $options = []) + public static function parse(Parser $parser, TokensList $list, array $options = []): ArrayObj|array { $ret = empty($options['type']) ? new static() : []; diff --git a/src/Components/CaseExpression.php b/src/Components/CaseExpression.php index 0ff0ab0a4..406f9cdee 100644 --- a/src/Components/CaseExpression.php +++ b/src/Components/CaseExpression.php @@ -70,10 +70,8 @@ final class CaseExpression implements Component * @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 CaseExpression */ - public static function parse(Parser $parser, TokensList $list, array $options = []) + public static function parse(Parser $parser, TokensList $list, array $options = []): CaseExpression { $ret = new static(); diff --git a/src/Components/CreateDefinition.php b/src/Components/CreateDefinition.php index a263abb6c..a5e62793f 100644 --- a/src/Components/CreateDefinition.php +++ b/src/Components/CreateDefinition.php @@ -180,7 +180,7 @@ public function __construct( * * @return CreateDefinition[] */ - public static function parse(Parser $parser, TokensList $list, array $options = []) + public static function parse(Parser $parser, TokensList $list, array $options = []): array { $ret = []; diff --git a/src/Components/DataType.php b/src/Components/DataType.php index 53cfd6550..226213c6b 100644 --- a/src/Components/DataType.php +++ b/src/Components/DataType.php @@ -93,10 +93,8 @@ public function __construct( * @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 DataType|null */ - public static function parse(Parser $parser, TokensList $list, array $options = []) + public static function parse(Parser $parser, TokensList $list, array $options = []): DataType|null { $ret = new static(); diff --git a/src/Components/FunctionCall.php b/src/Components/FunctionCall.php index b3b7590c7..88b269995 100644 --- a/src/Components/FunctionCall.php +++ b/src/Components/FunctionCall.php @@ -48,10 +48,8 @@ public function __construct($name = null, $parameters = null) * @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 FunctionCall */ - public static function parse(Parser $parser, TokensList $list, array $options = []) + public static function parse(Parser $parser, TokensList $list, array $options = []): FunctionCall { $ret = new static(); diff --git a/src/Components/IntoKeyword.php b/src/Components/IntoKeyword.php index 493a53e75..00c7ac89a 100644 --- a/src/Components/IntoKeyword.php +++ b/src/Components/IntoKeyword.php @@ -137,10 +137,8 @@ public function __construct( * @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 IntoKeyword */ - public static function parse(Parser $parser, TokensList $list, array $options = []) + public static function parse(Parser $parser, TokensList $list, array $options = []): IntoKeyword { $ret = new static(); diff --git a/src/Components/Key.php b/src/Components/Key.php index a1c64a25f..daa6469f5 100644 --- a/src/Components/Key.php +++ b/src/Components/Key.php @@ -123,10 +123,8 @@ public function __construct( * @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 Key */ - public static function parse(Parser $parser, TokensList $list, array $options = []) + public static function parse(Parser $parser, TokensList $list, array $options = []): Key { $ret = new static(); diff --git a/src/Components/Limit.php b/src/Components/Limit.php index b51679d5a..9f46c537a 100644 --- a/src/Components/Limit.php +++ b/src/Components/Limit.php @@ -42,10 +42,8 @@ public function __construct($rowCount = 0, $offset = 0) * @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 Limit */ - public static function parse(Parser $parser, TokensList $list, array $options = []) + public static function parse(Parser $parser, TokensList $list, array $options = []): Limit { $ret = new static(); diff --git a/src/Components/LockExpression.php b/src/Components/LockExpression.php index af54d4b17..1c9c1beb5 100644 --- a/src/Components/LockExpression.php +++ b/src/Components/LockExpression.php @@ -34,10 +34,8 @@ final class LockExpression implements Component * @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 LockExpression */ - public static function parse(Parser $parser, TokensList $list, array $options = []) + public static function parse(Parser $parser, TokensList $list, array $options = []): LockExpression { $ret = new static(); @@ -109,10 +107,7 @@ public static function buildAll(array $component): string return implode(', ', $component); } - /** - * @return string - */ - private static function parseLockType(Parser $parser, TokensList $list) + private static function parseLockType(Parser $parser, TokensList $list): string { $lockType = ''; diff --git a/src/Components/OptionsArray.php b/src/Components/OptionsArray.php index 17c067437..17188cfc7 100644 --- a/src/Components/OptionsArray.php +++ b/src/Components/OptionsArray.php @@ -37,10 +37,8 @@ public function __construct(public array $options = []) * @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 OptionsArray */ - public static function parse(Parser $parser, TokensList $list, array $options = []) + public static function parse(Parser $parser, TokensList $list, array $options = []): OptionsArray { $ret = new static(); @@ -295,10 +293,8 @@ public static function build($component): string * @param string $key the key to be checked * @param bool $getExpr Gets the expression instead of the value. * The value is the processed form of the expression. - * - * @return mixed */ - public function has($key, $getExpr = false) + public function has($key, $getExpr = false): mixed { foreach ($this->options as $option) { if (is_array($option)) { diff --git a/src/Components/PartitionDefinition.php b/src/Components/PartitionDefinition.php index 8f312765c..f7ca0cfaf 100644 --- a/src/Components/PartitionDefinition.php +++ b/src/Components/PartitionDefinition.php @@ -110,10 +110,8 @@ final class PartitionDefinition implements Component * @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 PartitionDefinition */ - public static function parse(Parser $parser, TokensList $list, array $options = []) + public static function parse(Parser $parser, TokensList $list, array $options = []): PartitionDefinition { $ret = new static(); diff --git a/src/Components/Reference.php b/src/Components/Reference.php index 1b1ca128d..659f5941f 100644 --- a/src/Components/Reference.php +++ b/src/Components/Reference.php @@ -76,10 +76,8 @@ public function __construct($table = null, array $columns = [], $options = null) * @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 Reference */ - public static function parse(Parser $parser, TokensList $list, array $options = []) + public static function parse(Parser $parser, TokensList $list, array $options = []): Reference { $ret = new static(); diff --git a/src/Components/UnionKeyword.php b/src/Components/UnionKeyword.php index c13f7852e..427929827 100644 --- a/src/Components/UnionKeyword.php +++ b/src/Components/UnionKeyword.php @@ -24,11 +24,9 @@ final class UnionKeyword implements Component * @param TokensList $list the list of tokens that are being parsed * @param array $options parameters for parsing * - * @return mixed - * * @throws RuntimeException not implemented yet. */ - public static function parse(Parser $parser, TokensList $list, array $options = []) + public static function parse(Parser $parser, TokensList $list, array $options = []): mixed { throw new RuntimeException(Translator::gettext('Not implemented yet.')); } diff --git a/src/Components/WithKeyword.php b/src/Components/WithKeyword.php index ca644a122..cc204b3f8 100644 --- a/src/Components/WithKeyword.php +++ b/src/Components/WithKeyword.php @@ -36,11 +36,9 @@ public function __construct(string $name) * @param TokensList $list the list of tokens that are being parsed * @param array $options parameters for parsing * - * @return mixed - * * @throws RuntimeException not implemented yet. */ - public static function parse(Parser $parser, TokensList $list, array $options = []) + public static function parse(Parser $parser, TokensList $list, array $options = []): mixed { throw new RuntimeException(Translator::gettext('Not implemented yet.')); } diff --git a/src/Context.php b/src/Context.php index 42c393244..725e915e2 100644 --- a/src/Context.php +++ b/src/Context.php @@ -670,10 +670,8 @@ private static function getModeFromString(string $mode): int * * @param string $str the string to be escaped * @param string $quote quote to be used when escaping - * - * @return string */ - public static function escape(string $str, string $quote = '`') + public static function escape(string $str, string $quote = '`'): string { if ((static::$mode & self::SQL_MODE_NO_ENCLOSING_QUOTES) && (! static::isKeyword($str, true))) { return $str; diff --git a/src/Core.php b/src/Core.php index ffa8bc429..775b686ac 100644 --- a/src/Core.php +++ b/src/Core.php @@ -47,11 +47,9 @@ public function __construct() * * @param Exception $error the error exception * - * @return void - * * @throws Exception throws the exception, if strict mode is enabled. */ - public function error($error) + public function error($error): void { if ($this->strict) { throw $error; diff --git a/src/Lexer.php b/src/Lexer.php index 98a24231a..b8ced2c0f 100644 --- a/src/Lexer.php +++ b/src/Lexer.php @@ -158,10 +158,8 @@ class Lexer extends Core * @param bool $strict whether strict mode should be * enabled or not * @param string $delimiter the delimiter to be used - * - * @return TokensList */ - public static function getTokens($str, $strict = false, $delimiter = null) + public static function getTokens($str, $strict = false, $delimiter = null): TokensList { $lexer = new self($str, $strict, $delimiter); @@ -456,10 +454,8 @@ public function error($msg, $str = '', $pos = 0, $code = 0): void /** * Parses a keyword. - * - * @return Token|null */ - public function parseKeyword() + public function parseKeyword(): Token|null { $token = ''; @@ -518,10 +514,8 @@ public function parseKeyword() /** * Parses a label. - * - * @return Token|null */ - public function parseLabel() + public function parseLabel(): Token|null { $token = ''; @@ -564,10 +558,8 @@ public function parseLabel() /** * Parses an operator. - * - * @return Token|null */ - public function parseOperator() + public function parseOperator(): Token|null { $token = ''; @@ -602,10 +594,8 @@ public function parseOperator() /** * Parses a whitespace. - * - * @return Token|null */ - public function parseWhitespace() + public function parseWhitespace(): Token|null { $token = $this->str[$this->last]; @@ -624,10 +614,8 @@ public function parseWhitespace() /** * Parses a comment. - * - * @return Token|null */ - public function parseComment() + public function parseComment(): Token|null { $iBak = $this->last; $token = $this->str[$this->last]; @@ -743,10 +731,8 @@ public function parseComment() /** * Parses a boolean. - * - * @return Token|null */ - public function parseBool() + public function parseBool(): Token|null { if ($this->last + 3 >= $this->len) { // At least `min(strlen('TRUE'), strlen('FALSE'))` characters are @@ -776,10 +762,8 @@ public function parseBool() /** * Parses a number. - * - * @return Token|null */ - public function parseNumber() + public function parseNumber(): Token|null { // A rudimentary state machine is being used to parse numbers due to // the various forms of their notation. @@ -943,11 +927,9 @@ public function parseNumber() * * @param string $quote additional starting symbol * - * @return Token|null - * * @throws LexerException */ - public function parseString($quote = '') + public function parseString($quote = ''): Token|null { $token = $this->str[$this->last]; $flags = Context::isString($token); @@ -995,11 +977,9 @@ public function parseString($quote = '') /** * Parses a symbol. * - * @return Token|null - * * @throws LexerException */ - public function parseSymbol() + public function parseSymbol(): Token|null { $token = $this->str[$this->last]; $flags = Context::isSymbol($token); @@ -1045,10 +1025,8 @@ public function parseSymbol() /** * Parses unknown parts of the query. - * - * @return Token|null */ - public function parseUnknown() + public function parseUnknown(): Token|null { $token = $this->str[$this->last]; if (Context::isSeparator($token)) { @@ -1073,10 +1051,8 @@ public function parseUnknown() /** * Parses the delimiter of the query. - * - * @return Token|null */ - public function parseDelimiter() + public function parseDelimiter(): Token|null { $idx = 0; diff --git a/src/Statement.php b/src/Statement.php index d0e679d7f..cfad96ff6 100644 --- a/src/Statement.php +++ b/src/Statement.php @@ -454,10 +454,8 @@ public function getClauses(): array * Builds the string representation of this statement. * * @see static::build - * - * @return string */ - public function __toString() + public function __toString(): string { return $this->build(); } diff --git a/src/Statements/LoadStatement.php b/src/Statements/LoadStatement.php index f3d07c39a..202654ab8 100644 --- a/src/Statements/LoadStatement.php +++ b/src/Statements/LoadStatement.php @@ -336,10 +336,8 @@ public function parseFileOptions(Parser $parser, TokensList $list, $keyword = 'F * @param Parser $parser * @param TokensList $list * @param int $state - * - * @return int */ - public function parseKeywordsAccordingToState($parser, $list, $state) + public function parseKeywordsAccordingToState($parser, $list, $state): int { $token = $list->tokens[$list->idx]; diff --git a/src/Statements/PurgeStatement.php b/src/Statements/PurgeStatement.php index b8302cdbe..10cf6b31b 100644 --- a/src/Statements/PurgeStatement.php +++ b/src/Statements/PurgeStatement.php @@ -122,10 +122,8 @@ public function parse(Parser $parser, TokensList $list): void * @param Parser $parser the instance that requests parsing * @param Token $token token to be parsed * @param string[] $expectedKeywords array of possibly expected keywords at this point - * - * @return mixed|null */ - private static function parseExpectedKeyword($parser, $token, $expectedKeywords) + private static function parseExpectedKeyword($parser, $token, $expectedKeywords): mixed { if ($token->type === Token::TYPE_KEYWORD) { if (in_array($token->keyword, $expectedKeywords)) { diff --git a/src/Token.php b/src/Token.php index 27b0f6371..bdd2fbb06 100644 --- a/src/Token.php +++ b/src/Token.php @@ -228,10 +228,8 @@ public function __construct($token, $type = 0, $flags = 0) * Does little processing to the token to extract a value. * * If no processing can be done it will return the initial string. - * - * @return mixed */ - public function extract() + public function extract(): mixed { switch ($this->type) { case self::TYPE_KEYWORD: diff --git a/src/TokensList.php b/src/TokensList.php index 39af9204b..d669bda4c 100644 --- a/src/TokensList.php +++ b/src/TokensList.php @@ -93,10 +93,8 @@ public function add(Token $token): void /** * Gets the next token. Skips any irrelevant token (whitespaces and * comments). - * - * @return Token|null */ - public function getNext() + public function getNext(): Token|null { for (; $this->idx < $this->count; ++$this->idx) { if ( @@ -132,10 +130,8 @@ public function getPrevious(): Token|null * Gets the previous token. * * @param int|int[] $type the type - * - * @return Token|null */ - public function getPreviousOfType($type) + public function getPreviousOfType($type): Token|null { if (! is_array($type)) { $type = [$type]; @@ -154,10 +150,8 @@ public function getPreviousOfType($type) * Gets the next token. * * @param int|int[] $type the type - * - * @return Token|null */ - public function getNextOfType($type) + public function getNextOfType($type): Token|null { if (! is_array($type)) { $type = [$type]; @@ -177,10 +171,8 @@ public function getNextOfType($type) * * @param int $type the type of the token * @param string $value the value of the token - * - * @return Token|null */ - public function getNextOfTypeAndValue($type, $value) + public function getNextOfTypeAndValue($type, $value): Token|null { for (; $this->idx < $this->count; ++$this->idx) { if (($this->tokens[$this->idx]->type === $type) && ($this->tokens[$this->idx]->value === $value)) { diff --git a/src/Tools/ContextGenerator.php b/src/Tools/ContextGenerator.php index db385cad9..3fbe7c9f5 100644 --- a/src/Tools/ContextGenerator.php +++ b/src/Tools/ContextGenerator.php @@ -145,7 +145,7 @@ public static function sortWords(array &$arr): array * * @return array>> */ - public static function readWords(array $files) + public static function readWords(array $files): array { $words = []; foreach ($files as $file) { @@ -279,10 +279,8 @@ public static function generate($options): string * Formats context name. * * @param string $name name to format - * - * @return string */ - public static function formatName($name) + public static function formatName($name): string { /* Split name and version */ $parts = []; diff --git a/src/Tools/TestGenerator.php b/src/Tools/TestGenerator.php index d64da4423..2056deb00 100644 --- a/src/Tools/TestGenerator.php +++ b/src/Tools/TestGenerator.php @@ -132,10 +132,8 @@ public static function generate($query, $type = 'parser'): array * @param string $output the output file * @param string $debug the debug file * @param bool $ansi activate quotes ANSI mode - * - * @return void */ - public static function build($type, $input, $output, $debug = null, $ansi = false) + public static function build($type, $input, $output, $debug = null, $ansi = false): void { // Support query types: `lexer` / `parser`. if (! in_array($type, ['lexer', 'parser'])) { diff --git a/src/Translator.php b/src/Translator.php index b4876a462..f693bb9a9 100644 --- a/src/Translator.php +++ b/src/Translator.php @@ -63,7 +63,7 @@ public static function load(): void * * @return string translated string (or original, if not found) */ - public static function gettext($msgid) + public static function gettext($msgid): string { if (! class_exists(Loader::class, true)) { return $msgid; diff --git a/src/UtfString.php b/src/UtfString.php index 59d2f436f..e2aa00b69 100644 --- a/src/UtfString.php +++ b/src/UtfString.php @@ -318,20 +318,16 @@ public static function getCharLength($byte): int /** * Returns the length in characters of the string. - * - * @return int */ - public function length() + public function length(): int { return $this->charLen; } /** * Returns the contained string. - * - * @return string */ - public function __toString() + public function __toString(): string { return $this->str; } diff --git a/src/Utils/BufferedQuery.php b/src/Utils/BufferedQuery.php index c12155b69..5be54ed21 100644 --- a/src/Utils/BufferedQuery.php +++ b/src/Utils/BufferedQuery.php @@ -120,10 +120,8 @@ public function setDelimiter($delimiter): void * Extracts a statement from the buffer. * * @param bool $end whether the end of the buffer was reached - * - * @return string|false */ - public function extract($end = false) + public function extract($end = false): string|false { /** * The last parsed position. diff --git a/src/Utils/Formatter.php b/src/Utils/Formatter.php index 3f1238383..f5227a808 100644 --- a/src/Utils/Formatter.php +++ b/src/Utils/Formatter.php @@ -92,7 +92,7 @@ public function __construct(array $options = []) * * @return array>> */ - protected function getMergedOptions(array $options) + protected function getMergedOptions(array $options): array { $options = array_merge( $this->getDefaultOptions(), @@ -324,10 +324,8 @@ private static function mergeFormats(array $formats, array $newFormats): array * Formats the given list of tokens. * * @param TokensList $list the list of tokens - * - * @return string */ - public function formatList($list) + public function formatList($list): string { /** * The query to be returned. @@ -636,10 +634,8 @@ public function escapeConsole(string $string): string * Tries to print the query and returns the result. * * @param Token $token the token to be printed - * - * @return string */ - public function toString($token) + public function toString($token): string { $text = $token->token; static $prev; @@ -698,7 +694,7 @@ public function toString($token) * * @return string the formatted string */ - public static function format($query, array $options = []) + public static function format($query, array $options = []): string { $lexer = new Lexer($query); $formatter = new self($options); @@ -712,10 +708,8 @@ public static function format($query, array $options = []) * A group is delimited by a pair of brackets. * * @param TokensList $list the list of tokens - * - * @return int */ - public static function getGroupLength($list) + public static function getGroupLength($list): int { /** * The number of opening brackets found. diff --git a/src/Utils/Query.php b/src/Utils/Query.php index 81a53d32c..17277bf51 100644 --- a/src/Utils/Query.php +++ b/src/Utils/Query.php @@ -287,7 +287,7 @@ class Query * @return array * @psalm-return QueryFlagsType */ - private static function getFlagsSelect(SelectStatement $statement, $flags) + private static function getFlagsSelect(SelectStatement $statement, $flags): array { $flags['querytype'] = 'SELECT'; $flags['is_select'] = true; @@ -363,7 +363,7 @@ private static function getFlagsSelect(SelectStatement $statement, $flags) * @return array * @psalm-return QueryFlagsType */ - public static function getFlags($statement, $all = false) + public static function getFlags($statement, $all = false): array { $flags = ['querytype' => false]; if ($all) { @@ -470,7 +470,7 @@ public static function getFlags($statement, $all = false) * statement?: Statement|null, parser?: Parser * } */ - public static function getAll($query) + public static function getAll($query): array { $parser = new Parser($query); @@ -558,7 +558,7 @@ public static function getAll($query) * * @return array */ - public static function getTables($statement) + public static function getTables($statement): array { $expressions = []; @@ -882,10 +882,8 @@ public static function getFirstStatement($query, $delimiter = null): array * @param Statement $statement the parsed query that has to be modified * @param TokensList $list the list of tokens * @param string $clause the clause to be returned - * - * @return int */ - public static function getClauseStartOffset($statement, $list, $clause) + public static function getClauseStartOffset($statement, $list, $clause): int { /** * The count of brackets. diff --git a/src/Utils/Table.php b/src/Utils/Table.php index 7bca9fd8e..fe4082543 100644 --- a/src/Utils/Table.php +++ b/src/Utils/Table.php @@ -21,7 +21,7 @@ class Table * * @return array> */ - public static function getForeignKeys($statement) + public static function getForeignKeys($statement): array { if (empty($statement->fields) || (! is_array($statement->fields)) || (! $statement->options->has('TABLE'))) { return []; @@ -79,7 +79,7 @@ public static function getForeignKeys($statement) * * @return array> */ - public static function getFields($statement) + public static function getFields($statement): array { if (empty($statement->fields) || (! is_array($statement->fields)) || (! $statement->options->has('TABLE'))) { return [];