Skip to content

Commit

Permalink
Add some more return types
Browse files Browse the repository at this point in the history
Signed-off-by: Kamil Tekiela <[email protected]>
  • Loading branch information
kamil-tekiela committed Aug 29, 2023
1 parent 52ffc49 commit b31d0a6
Show file tree
Hide file tree
Showing 14 changed files with 18 additions and 75 deletions.
10 changes: 0 additions & 10 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.14.1@b9d355e0829c397b9b3b47d0c0ed042a8a70284d">
<files psalm-version="5.15.0@5c774aca4746caf3d239d9c8cadb9f882ca29352">
<file src="src/Components/AlterOperation.php">
<InvalidPropertyAssignmentValue>
<code><![CDATA[[
Expand Down
8 changes: 2 additions & 6 deletions src/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,8 @@ public function __construct(Parser|null $parser = null, TokensList|null $list =

/**
* Builds the string representation of this statement.
*
* @return string
*/
public function build()
public function build(): string
{
/**
* Query to be returned.
Expand Down Expand Up @@ -472,11 +470,9 @@ public function __toString()
* @param Parser $parser the instance that requests parsing
* @param TokensList $list the list of tokens to be parsed
*
* @return bool
*
* @throws Exceptions\ParserException
*/
public function validateClauseOrder($parser, $list)
public function validateClauseOrder($parser, $list): bool
{
$clauses = array_flip(array_keys($this->getClauses()));

Expand Down
5 changes: 1 addition & 4 deletions src/Statements/DeleteStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
5 changes: 1 addition & 4 deletions src/Statements/InsertStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 1 addition & 4 deletions src/Statements/LoadStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 1 addition & 4 deletions src/Statements/NotImplementedStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ class NotImplementedStatement extends Statement
*/
public $unknown = [];

/**
* @return string
*/
public function build()
public function build(): string

Check warning on line 26 in src/Statements/NotImplementedStatement.php

View check run for this annotation

Codecov / codecov/patch

src/Statements/NotImplementedStatement.php#L26

Added line #L26 was not covered by tests
{
// Building the parsed part of the query (if any).
$query = parent::build() . ' ';
Expand Down
5 changes: 1 addition & 4 deletions src/Statements/ReplaceStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 1 addition & 4 deletions src/Statements/TransactionStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 1 addition & 4 deletions src/Statements/WithStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,7 @@ public function parse(Parser $parser, TokensList $list): void
--$list->idx;
}

/**
* {@inheritdoc}
*/
public function build()
public function build(): string
{
$str = 'WITH ';

Expand Down
16 changes: 3 additions & 13 deletions src/TokensList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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]);
Expand Down
2 changes: 1 addition & 1 deletion src/Tools/ContextGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class %2$s extends Context
*
* @return array<int, array<int, array<int, string>>>
*/
public static function sortWords(array &$arr)
public static function sortWords(array &$arr): array
{
ksort($arr);
foreach ($arr as &$wordsByLen) {
Expand Down
16 changes: 3 additions & 13 deletions src/UtfString.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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.');
}
Expand All @@ -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.');
}
Expand Down
4 changes: 1 addition & 3 deletions src/Utils/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -766,10 +766,8 @@ public static function replaceClause($statement, $list, $old, $new = null, $only
* @param array<int, array<int, string>> $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);

Expand Down

0 comments on commit b31d0a6

Please sign in to comment.