Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add remaining native return types #502

Merged
merged 1 commit into from
Aug 30, 2023
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
3 changes: 0 additions & 3 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint">
<severity>4</severity>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint">
<severity>4</severity>
</rule>
<rule ref="Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps">
<severity>4</severity>
</rule>
Expand Down
6 changes: 0 additions & 6 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -857,9 +857,6 @@
<code>$built[$field]</code>
<code><![CDATA[$parsedClauses[$token->value]]]></code>
</InvalidArgument>
<MethodSignatureMustProvideReturnType>
<code>__toString</code>
</MethodSignatureMustProvideReturnType>
<MixedArrayOffset>
<code><![CDATA[$parsedClauses[$token->value]]]></code>
<code><![CDATA[$parsedClauses[$token->value]]]></code>
Expand Down Expand Up @@ -1206,9 +1203,6 @@
</RedundantConditionGivenDocblockType>
</file>
<file src="src/UtfString.php">
<MethodSignatureMustProvideReturnType>
<code>__toString</code>
</MethodSignatureMustProvideReturnType>
<PossiblyUnusedProperty>
<code>$byteLen</code>
</PossiblyUnusedProperty>
Expand Down
4 changes: 1 addition & 3 deletions src/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, mixed> $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.
Expand Down
4 changes: 1 addition & 3 deletions src/Components/AlterOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,8 @@
* @param Parser $parser the parser that serves as context
* @param TokensList $list the list of tokens that are being parsed
* @param array<string, mixed> $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();

Expand Down Expand Up @@ -351,12 +349,12 @@

// Skipping comments.
if ($token->type === Token::TYPE_COMMENT) {
continue;

Check warning on line 352 in src/Components/AlterOperation.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.1

Escaped Mutant for Mutator "Continue_": --- Original +++ New @@ @@ } // Skipping comments. if ($token->type === Token::TYPE_COMMENT) { - continue; + break; } // Skipping whitespaces. if ($token->type === Token::TYPE_WHITESPACE) {
}

// Skipping whitespaces.
if ($token->type === Token::TYPE_WHITESPACE) {
if ($state === 2) {

Check warning on line 357 in src/Components/AlterOperation.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.1

Escaped Mutant for Mutator "DecrementInteger": --- Original +++ New @@ @@ } // Skipping whitespaces. if ($token->type === Token::TYPE_WHITESPACE) { - if ($state === 2) { + if ($state === 1) { // When parsing the unknown part, the whitespaces are // included to not break anything. $ret->unknown[] = $token;
// When parsing the unknown part, the whitespaces are
// included to not break anything.
$ret->unknown[] = $token;
Expand All @@ -370,7 +368,7 @@
// Not only when aliasing but also when parsing the body of an event, we just list the tokens of the
// body in the unknown tokens list, as they define their own statements.
if ($ret->options->has('AS') || $ret->options->has('DO')) {
for (; $list->idx < $list->count; ++$list->idx) {

Check warning on line 371 in src/Components/AlterOperation.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.1

Escaped Mutant for Mutator "LessThan": --- Original +++ New @@ @@ // Not only when aliasing but also when parsing the body of an event, we just list the tokens of the // body in the unknown tokens list, as they define their own statements. if ($ret->options->has('AS') || $ret->options->has('DO')) { - for (; $list->idx < $list->count; ++$list->idx) { + for (; $list->idx <= $list->count; ++$list->idx) { if ($list->tokens[$list->idx]->type === Token::TYPE_DELIMITER) { break; }
if ($list->tokens[$list->idx]->type === Token::TYPE_DELIMITER) {
break;
}
Expand Down Expand Up @@ -410,7 +408,7 @@

$state = 2;
} elseif ($state === 2) {
if (is_string($token->value) || is_numeric($token->value)) {

Check warning on line 411 in src/Components/AlterOperation.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.1

Escaped Mutant for Mutator "LogicalOr": --- Original +++ New @@ @@ } $state = 2; } elseif ($state === 2) { - if (is_string($token->value) || is_numeric($token->value)) { + if (is_string($token->value) && is_numeric($token->value)) { $arrayKey = $token->value; } else { $arrayKey = $token->token;

Check warning on line 411 in src/Components/AlterOperation.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.1

Escaped Mutant for Mutator "LogicalOrAllSubExprNegation": --- Original +++ New @@ @@ } $state = 2; } elseif ($state === 2) { - if (is_string($token->value) || is_numeric($token->value)) { + if (!is_string($token->value) || !is_numeric($token->value)) { $arrayKey = $token->value; } else { $arrayKey = $token->token;

Check warning on line 411 in src/Components/AlterOperation.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.1

Escaped Mutant for Mutator "LogicalOrNegation": --- Original +++ New @@ @@ } $state = 2; } elseif ($state === 2) { - if (is_string($token->value) || is_numeric($token->value)) { + if (!(is_string($token->value) || is_numeric($token->value))) { $arrayKey = $token->value; } else { $arrayKey = $token->token;

Check warning on line 411 in src/Components/AlterOperation.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.1

Escaped Mutant for Mutator "LogicalOrSingleSubExprNegation": --- Original +++ New @@ @@ } $state = 2; } elseif ($state === 2) { - if (is_string($token->value) || is_numeric($token->value)) { + if (!is_string($token->value) || is_numeric($token->value)) { $arrayKey = $token->value; } else { $arrayKey = $token->token;

Check warning on line 411 in src/Components/AlterOperation.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.1

Escaped Mutant for Mutator "LogicalOrSingleSubExprNegation": --- Original +++ New @@ @@ } $state = 2; } elseif ($state === 2) { - if (is_string($token->value) || is_numeric($token->value)) { + if (is_string($token->value) || !is_numeric($token->value)) { $arrayKey = $token->value; } else { $arrayKey = $token->token;
$arrayKey = $token->value;
} else {
$arrayKey = $token->token;
Expand Down Expand Up @@ -471,10 +469,10 @@
if (
($token->type === Token::TYPE_KEYWORD)
&& (($token->keyword === 'PARTITION BY')
|| ($token->keyword === 'PARTITION' && $nextToken && $nextToken->value !== '('))

Check warning on line 472 in src/Components/AlterOperation.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.1

Escaped Mutant for Mutator "LogicalAnd": --- Original +++ New @@ @@ $list->idx++; // Ignore the current token $nextToken = $list->getNext(); - if ($token->type === Token::TYPE_KEYWORD && ($token->keyword === 'PARTITION BY' || $token->keyword === 'PARTITION' && $nextToken && $nextToken->value !== '(')) { + if ($token->type === Token::TYPE_KEYWORD && ($token->keyword === 'PARTITION BY' || ($token->keyword === 'PARTITION' || $nextToken) && $nextToken->value !== '(')) { $partitionState = 1; } elseif ($token->type === Token::TYPE_KEYWORD && $token->keyword === 'PARTITION') { $partitionState = 2;
) {
$partitionState = 1;
} elseif (($token->type === Token::TYPE_KEYWORD) && ($token->keyword === 'PARTITION')) {

Check warning on line 475 in src/Components/AlterOperation.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.1

Escaped Mutant for Mutator "LogicalAnd": --- Original +++ New @@ @@ $nextToken = $list->getNext(); if ($token->type === Token::TYPE_KEYWORD && ($token->keyword === 'PARTITION BY' || $token->keyword === 'PARTITION' && $nextToken && $nextToken->value !== '(')) { $partitionState = 1; - } elseif ($token->type === Token::TYPE_KEYWORD && $token->keyword === 'PARTITION') { + } elseif ($token->type === Token::TYPE_KEYWORD || $token->keyword === 'PARTITION') { $partitionState = 2; } --$list->idx;
$partitionState = 2;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Components/ArrayObj.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() : [];

Expand Down
4 changes: 1 addition & 3 deletions src/Components/CaseExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, mixed> $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();

Expand Down
2 changes: 1 addition & 1 deletion src/Components/CreateDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand Down
4 changes: 1 addition & 3 deletions src/Components/DataType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, mixed> $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();

Expand Down
4 changes: 1 addition & 3 deletions src/Components/FunctionCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, mixed> $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();

Expand Down
4 changes: 1 addition & 3 deletions src/Components/IntoKeyword.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, mixed> $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();

Expand Down
4 changes: 1 addition & 3 deletions src/Components/Key.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, mixed> $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();

Expand Down
4 changes: 1 addition & 3 deletions src/Components/Limit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, mixed> $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();

Expand Down
9 changes: 2 additions & 7 deletions src/Components/LockExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, mixed> $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();

Expand Down Expand Up @@ -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 = '';

Expand Down
8 changes: 2 additions & 6 deletions src/Components/OptionsArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, mixed> $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();

Expand Down Expand Up @@ -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)) {
Expand Down
4 changes: 1 addition & 3 deletions src/Components/PartitionDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, mixed> $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();

Expand Down
4 changes: 1 addition & 3 deletions src/Components/Reference.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, mixed> $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();

Expand Down
4 changes: 1 addition & 3 deletions src/Components/UnionKeyword.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@
* @param TokensList $list the list of tokens that are being parsed
* @param array<string, mixed> $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

Check warning on line 29 in src/Components/UnionKeyword.php

View check run for this annotation

Codecov / codecov/patch

src/Components/UnionKeyword.php#L29

Added line #L29 was not covered by tests
{
throw new RuntimeException(Translator::gettext('Not implemented yet.'));
}
Expand Down
4 changes: 1 addition & 3 deletions src/Components/WithKeyword.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@
* @param TokensList $list the list of tokens that are being parsed
* @param array<string, mixed> $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

Check warning on line 41 in src/Components/WithKeyword.php

View check run for this annotation

Codecov / codecov/patch

src/Components/WithKeyword.php#L41

Added line #L41 was not covered by tests
{
throw new RuntimeException(Translator::gettext('Not implemented yet.'));
}
Expand Down
4 changes: 1 addition & 3 deletions src/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions src/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading
Loading