From b31d0a688201a2c1c8719ef1c15ce7cc2f793e66 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Tue, 29 Aug 2023 17:22:15 +0100 Subject: [PATCH] Add some more return types Signed-off-by: Kamil Tekiela --- phpstan-baseline.neon | 10 ---------- psalm-baseline.xml | 2 +- src/Statement.php | 8 ++------ src/Statements/DeleteStatement.php | 5 +---- src/Statements/InsertStatement.php | 5 +---- src/Statements/LoadStatement.php | 5 +---- src/Statements/NotImplementedStatement.php | 5 +---- src/Statements/ReplaceStatement.php | 5 +---- src/Statements/TransactionStatement.php | 5 +---- src/Statements/WithStatement.php | 5 +---- src/TokensList.php | 16 +++------------- src/Tools/ContextGenerator.php | 2 +- src/UtfString.php | 16 +++------------- src/Utils/Query.php | 4 +--- 14 files changed, 18 insertions(+), 75 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index a5f50405d..fcc9a6308 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -925,16 +925,6 @@ parameters: count: 2 path: tests/Components/PartitionDefinitionTest.php - - - message: "#^Call to method PHPUnit\\\\Framework\\\\Assert\\:\\:assertArrayHasKey\\(\\) with 2 and PhpMyAdmin\\\\SqlParser\\\\TokensList will always evaluate to false\\.$#" - count: 1 - path: tests/Lexer/TokensListTest.php - - - - message: "#^Call to method PHPUnit\\\\Framework\\\\Assert\\:\\:assertArrayHasKey\\(\\) with 112 and PhpMyAdmin\\\\SqlParser\\\\UtfString will always evaluate to false\\.$#" - count: 1 - path: tests/Misc/UtfStringTest.php - - message: "#^Cannot call method has\\(\\) on PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null\\.$#" count: 1 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index cf3c3d26f..e442ecfe0 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,5 +1,5 @@ - + getClauses())); diff --git a/src/Statements/DeleteStatement.php b/src/Statements/DeleteStatement.php index 6a6a105d2..43451fbd1 100644 --- a/src/Statements/DeleteStatement.php +++ b/src/Statements/DeleteStatement.php @@ -157,10 +157,7 @@ class DeleteStatement extends Statement */ public $limit; - /** - * @return string - */ - public function build() + public function build(): string { $ret = 'DELETE ' . OptionsArray::build($this->options); diff --git a/src/Statements/InsertStatement.php b/src/Statements/InsertStatement.php index 87b667208..7c7ae5490 100644 --- a/src/Statements/InsertStatement.php +++ b/src/Statements/InsertStatement.php @@ -111,10 +111,7 @@ class InsertStatement extends Statement */ public array|null $onDuplicateSet = null; - /** - * @return string - */ - public function build() + public function build(): string { $ret = 'INSERT ' . $this->options; $ret = trim($ret) . ' INTO ' . $this->into; diff --git a/src/Statements/LoadStatement.php b/src/Statements/LoadStatement.php index 508bc0b07..f3d07c39a 100644 --- a/src/Statements/LoadStatement.php +++ b/src/Statements/LoadStatement.php @@ -179,10 +179,7 @@ class LoadStatement extends Statement */ public $linesRows; - /** - * @return string - */ - public function build() + public function build(): string { $ret = 'LOAD DATA ' . $this->options . ' INFILE ' . $this->fileName; diff --git a/src/Statements/NotImplementedStatement.php b/src/Statements/NotImplementedStatement.php index 22b9ced92..469b1d4f9 100644 --- a/src/Statements/NotImplementedStatement.php +++ b/src/Statements/NotImplementedStatement.php @@ -23,10 +23,7 @@ class NotImplementedStatement extends Statement */ public $unknown = []; - /** - * @return string - */ - public function build() + public function build(): string { // Building the parsed part of the query (if any). $query = parent::build() . ' '; diff --git a/src/Statements/ReplaceStatement.php b/src/Statements/ReplaceStatement.php index a3ca0e3b3..00d54d481 100644 --- a/src/Statements/ReplaceStatement.php +++ b/src/Statements/ReplaceStatement.php @@ -81,10 +81,7 @@ class ReplaceStatement extends Statement */ public $select; - /** - * @return string - */ - public function build() + public function build(): string { $ret = 'REPLACE ' . $this->options; $ret = trim($ret) . ' INTO ' . $this->into; diff --git a/src/Statements/TransactionStatement.php b/src/Statements/TransactionStatement.php index 46140c34d..94afcc9dd 100644 --- a/src/Statements/TransactionStatement.php +++ b/src/Statements/TransactionStatement.php @@ -80,10 +80,7 @@ public function parse(Parser $parser, TokensList $list): void } } - /** - * @return string - */ - public function build() + public function build(): string { $ret = OptionsArray::build($this->options); if ($this->type === self::TYPE_BEGIN) { diff --git a/src/Statements/WithStatement.php b/src/Statements/WithStatement.php index 8d9fb4229..7e0ea1e0e 100644 --- a/src/Statements/WithStatement.php +++ b/src/Statements/WithStatement.php @@ -266,10 +266,7 @@ public function parse(Parser $parser, TokensList $list): void --$list->idx; } - /** - * {@inheritdoc} - */ - public function build() + public function build(): string { $str = 'WITH '; diff --git a/src/TokensList.php b/src/TokensList.php index 4d5f47b60..39af9204b 100644 --- a/src/TokensList.php +++ b/src/TokensList.php @@ -59,10 +59,8 @@ public function __construct(array $tokens = [], $count = -1) * Builds an array of tokens by merging their raw value. * * @param string|Token[]|TokensList $list the tokens to be built - * - * @return string */ - public static function build($list) + public static function build($list): string { if (is_string($list)) { return $list; @@ -216,7 +214,6 @@ public function getNextOfTypeAndFlag(int $type, int $flag): Token|null * @param int|null $offset the offset to be set * @param Token $value the token to be saved */ - #[\ReturnTypeWillChange] public function offsetSet($offset, $value): void { if ($offset === null) { @@ -230,11 +227,8 @@ public function offsetSet($offset, $value): void * Gets a value from the container. * * @param int $offset the offset to be returned - * - * @return Token|null */ - #[\ReturnTypeWillChange] - public function offsetGet($offset) + public function offsetGet($offset): Token|null { return $offset < $this->count ? $this->tokens[$offset] : null; } @@ -243,11 +237,8 @@ public function offsetGet($offset) * Checks if an offset was previously set. * * @param int $offset the offset to be checked - * - * @return bool */ - #[\ReturnTypeWillChange] - public function offsetExists($offset) + public function offsetExists($offset): bool { return $offset < $this->count; } @@ -257,7 +248,6 @@ public function offsetExists($offset) * * @param int $offset the offset to be unset */ - #[\ReturnTypeWillChange] public function offsetUnset($offset): void { unset($this->tokens[$offset]); diff --git a/src/Tools/ContextGenerator.php b/src/Tools/ContextGenerator.php index bf2c5a9b5..db385cad9 100644 --- a/src/Tools/ContextGenerator.php +++ b/src/Tools/ContextGenerator.php @@ -125,7 +125,7 @@ class %2$s extends Context * * @return array>> */ - public static function sortWords(array &$arr) + public static function sortWords(array &$arr): array { ksort($arr); foreach ($arr as &$wordsByLen) { diff --git a/src/UtfString.php b/src/UtfString.php index bac500e43..59d2f436f 100644 --- a/src/UtfString.php +++ b/src/UtfString.php @@ -200,7 +200,6 @@ public function __construct($str) * * @param int $offset the offset to be checked */ - #[\ReturnTypeWillChange] public function offsetExists($offset): bool { return ($offset >= 0) && ($offset < $this->charLen); @@ -210,11 +209,8 @@ public function offsetExists($offset): bool * Gets the character at given offset. * * @param int $offset the offset to be returned - * - * @return string|null */ - #[\ReturnTypeWillChange] - public function offsetGet($offset) + public function offsetGet($offset): string|null { if (($offset < 0) || ($offset >= $this->charLen)) { return null; @@ -255,12 +251,9 @@ public function offsetGet($offset) * @param int $offset the offset to be set * @param string $value the value to be set * - * @return void - * * @throws Exception not implemented. */ - #[\ReturnTypeWillChange] - public function offsetSet($offset, $value) + public function offsetSet($offset, $value): void { throw new Exception('Not implemented.'); } @@ -270,12 +263,9 @@ public function offsetSet($offset, $value) * * @param int $offset the value to be unset * - * @return void - * * @throws Exception not implemented. */ - #[\ReturnTypeWillChange] - public function offsetUnset($offset) + public function offsetUnset($offset): void { throw new Exception('Not implemented.'); } diff --git a/src/Utils/Query.php b/src/Utils/Query.php index 6268f0238..81a53d32c 100644 --- a/src/Utils/Query.php +++ b/src/Utils/Query.php @@ -766,10 +766,8 @@ public static function replaceClause($statement, $list, $old, $new = null, $only * @param array> $ops Clauses to be replaced. Contains multiple * arrays having two values: [$old, $new]. * Clauses must be sorted. - * - * @return string */ - public static function replaceClauses($statement, $list, array $ops) + public static function replaceClauses($statement, $list, array $ops): string { $count = count($ops);