Skip to content
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
"phpstan/phpstan-strict-rules": "^2.0.10",
"phpunit/phpunit": "^11.5",
"psalm/plugin-phpunit": "^0.19.6",
"vimeo/psalm": "^6.16.1",
"zumba/json-serializer": "~3.2.4"
"vimeo/psalm": "^6.16.1"
},
"conflict": {
"phpmyadmin/motranslator": "<5.2"
Expand Down
132 changes: 0 additions & 132 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -1644,90 +1644,6 @@ parameters:
count: 1
path: src/Tools/ContextGenerator.php

-
message: '#^Binary operation "\." between ''Unable to find…'' and mixed results in an error\.$#'
identifier: binaryOp.invalid
count: 1
path: src/Tools/CustomJsonSerializer.php

-
message: '#^Binary operation "\." between non\-falsy\-string and mixed results in an error\.$#'
identifier: binaryOp.invalid
count: 1
path: src/Tools/CustomJsonSerializer.php

-
message: '#^Cannot access offset 0 on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 1
path: src/Tools/CustomJsonSerializer.php

-
message: '#^Cannot call method unserialize\(\) on mixed\.$#'
identifier: method.nonObject
count: 1
path: src/Tools/CustomJsonSerializer.php

-
message: '#^Method PhpMyAdmin\\SqlParser\\Tools\\CustomJsonSerializer\:\:extractObjectData\(\) has parameter \$ref with generic class ReflectionClass but does not specify its types\: T$#'
identifier: missingType.generics
count: 1
path: src/Tools/CustomJsonSerializer.php

-
message: '#^Method PhpMyAdmin\\SqlParser\\Tools\\CustomJsonSerializer\:\:unserializeObject\(\) should return object but returns mixed\.$#'
identifier: return.type
count: 4
path: src/Tools/CustomJsonSerializer.php

-
message: '#^Parameter \#1 \$class of function class_exists expects string, mixed given\.$#'
identifier: argument.type
count: 1
path: src/Tools/CustomJsonSerializer.php

-
message: '#^Parameter \#1 \$data of method SplDoublyLinkedList\<mixed\>\:\:unserialize\(\) expects string, mixed given\.$#'
identifier: argument.type
count: 1
path: src/Tools/CustomJsonSerializer.php

-
message: '#^Parameter \#1 \$key of function array_key_exists expects int\|string, mixed given\.$#'
identifier: argument.type
count: 1
path: src/Tools/CustomJsonSerializer.php

-
message: '#^Parameter \#1 \$string of function substr expects string, mixed given\.$#'
identifier: argument.type
count: 1
path: src/Tools/CustomJsonSerializer.php

-
message: '#^Parameter \#2 \$name of method Zumba\\JsonSerializer\\JsonSerializer\:\:getReflectionProperty\(\) expects string, \(int\|string\) given\.$#'
identifier: argument.type
count: 1
path: src/Tools/CustomJsonSerializer.php

-
message: '#^Parameter \#3 \$properties \(array\<string\>\) of method PhpMyAdmin\\SqlParser\\Tools\\CustomJsonSerializer\:\:extractObjectData\(\) should be contravariant with parameter \$properties \(array\) of method Zumba\\JsonSerializer\\JsonSerializer\:\:extractObjectData\(\)$#'
identifier: method.childParameterType
count: 1
path: src/Tools/CustomJsonSerializer.php

-
message: '#^Variable \$ref might not be defined\.$#'
identifier: variable.undefined
count: 1
path: src/Tools/CustomJsonSerializer.php

-
message: '#^Variable property access on object\.$#'
identifier: property.dynamicName
count: 2
path: src/Tools/CustomJsonSerializer.php

-
message: '#^Argument of an invalid type list\<string\>\|false supplied for foreach, only iterables are supported\.$#'
identifier: foreach.nonIterable
Expand Down Expand Up @@ -2619,54 +2535,6 @@ parameters:
count: 5
path: tests/Parser/WithStatementTest.php

-
message: '#^Construct empty\(\) is not allowed\. Use more strict comparison\.$#'
identifier: empty.notAllowed
count: 1
path: tests/TestCase.php

-
message: '#^Dynamic call to static method PHPUnit\\Framework\\Assert\:\:assertArrayHasKey\(\)\.$#'
identifier: staticMethod.dynamicCall
count: 6
path: tests/TestCase.php

-
message: '#^Dynamic call to static method PHPUnit\\Framework\\Assert\:\:assertEquals\(\)\.$#'
identifier: staticMethod.dynamicCall
count: 4
path: tests/TestCase.php

-
message: '#^Dynamic call to static method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\)\.$#'
identifier: staticMethod.dynamicCall
count: 2
path: tests/TestCase.php

-
message: '#^Dynamic call to static method PHPUnit\\Framework\\Assert\:\:assertIsArray\(\)\.$#'
identifier: staticMethod.dynamicCall
count: 2
path: tests/TestCase.php

-
message: '#^Dynamic call to static method PHPUnit\\Framework\\Assert\:\:assertIsList\(\)\.$#'
identifier: staticMethod.dynamicCall
count: 2
path: tests/TestCase.php

-
message: '#^Dynamic call to static method PHPUnit\\Framework\\Assert\:\:assertIsString\(\)\.$#'
identifier: staticMethod.dynamicCall
count: 3
path: tests/TestCase.php

-
message: '#^Method PhpMyAdmin\\SqlParser\\Tests\\TestCase\:\:getData\(\) should return array\{query\: string, lexer\: PhpMyAdmin\\SqlParser\\Lexer, parser\: PhpMyAdmin\\SqlParser\\Parser\|null, errors\: array\{lexer\: list\<array\{string, string, int, int\}\>, parser\: list\<array\{string, PhpMyAdmin\\SqlParser\\Token, int\}\>\}\} but returns non\-empty\-array\.$#'
identifier: return.type
count: 1
path: tests/TestCase.php

-
message: '#^Dynamic call to static method PHPUnit\\Framework\\Assert\:\:assertEquals\(\)\.$#'
identifier: staticMethod.dynamicCall
Expand Down
74 changes: 5 additions & 69 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@
<code><![CDATA[$this->old]]></code>
</PossiblyNullOperand>
</file>
<file src="src/Components/WithKeyword.php">
<PossiblyUnusedReturnValue>
<code><![CDATA[string]]></code>
</PossiblyUnusedReturnValue>
</file>
<file src="src/Context.php">
<InvalidPropertyAssignmentValue>
<code><![CDATA[[]]]></code>
Expand Down Expand Up @@ -906,56 +911,6 @@
<code><![CDATA[$files]]></code>
</PossiblyFalseIterator>
</file>
<file src="src/Tools/CustomJsonSerializer.php">
<MixedArgument>
<code><![CDATA[$className]]></code>
<code><![CDATA[$className]]></code>
<code><![CDATA[$className]]></code>
<code><![CDATA[$ref]]></code>
<code><![CDATA[$value['value']]]></code>
</MixedArgument>
<MixedArgumentTypeCoercion>
<code><![CDATA[$property]]></code>
</MixedArgumentTypeCoercion>
<MixedArrayAccess>
<code><![CDATA[$className[0]]]></code>
</MixedArrayAccess>
<MixedAssignment>
<code><![CDATA[$data[$property]]]></code>
<code><![CDATA[$data[$property]]]></code>
<code><![CDATA[$obj]]></code>
<code><![CDATA[$obj]]></code>
<code><![CDATA[$obj]]></code>
<code><![CDATA[$propertyValue]]></code>
</MixedAssignment>
<MixedMethodCall>
<code><![CDATA[new $className()]]></code>
<code><![CDATA[unserialize]]></code>
</MixedMethodCall>
<MixedOperand>
<code><![CDATA[$className]]></code>
<code><![CDATA[$value['name']]]></code>
</MixedOperand>
<MixedReturnStatement>
<code><![CDATA[$obj]]></code>
<code><![CDATA[$obj]]></code>
<code><![CDATA[$obj]]></code>
<code><![CDATA[$this->objectMapping[$index]]]></code>
</MixedReturnStatement>
<MoreSpecificImplementedParamType>
<code><![CDATA[$properties]]></code>
</MoreSpecificImplementedParamType>
<PossiblyUndefinedVariable>
<code><![CDATA[$ref]]></code>
</PossiblyUndefinedVariable>
<PropertyNotSetInConstructor>
<code><![CDATA[CustomJsonSerializer]]></code>
</PropertyNotSetInConstructor>
<TypeDoesNotContainType>
<code><![CDATA[$className === 'DateTime']]></code>
<code><![CDATA[$className === 'DateTimeImmutable']]></code>
</TypeDoesNotContainType>
</file>
<file src="src/Tools/TestGenerator.php">
<MixedAssignment>
<code><![CDATA[$file]]></code>
Expand Down Expand Up @@ -1205,32 +1160,13 @@
<code><![CDATA[testBuildKill]]></code>
</InvalidArgument>
</file>
<file src="tests/TestCase.php">
<InvalidReturnStatement>
<code><![CDATA[$data]]></code>
</InvalidReturnStatement>
<InvalidReturnType>
<code><![CDATA[array{
* query: string,
* lexer: Lexer,
* parser: Parser|null,
* errors: array{lexer: list<array{string, string, int, int}>, parser: list<array{string, Token, int}>}
* }]]></code>
</InvalidReturnType>
</file>
<file src="tests/Tools/ContextGeneratorTest.php">
<PossiblyFalseOperand>
<code><![CDATA[getcwd()]]></code>
<code><![CDATA[getcwd()]]></code>
<code><![CDATA[getcwd()]]></code>
</PossiblyFalseOperand>
</file>
<file src="tests/UtfStringSerializer.php">
<PossiblyUnusedMethod>
<code><![CDATA[serialize]]></code>
<code><![CDATA[unserialize]]></code>
</PossiblyUnusedMethod>
</file>
<file src="tests/Utils/CLITest.php">
<UndefinedAttributeClass>
<code><![CDATA[AllowMockObjectsWithoutExpectations]]></code>
Expand Down
9 changes: 2 additions & 7 deletions src/Components/AlterOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace PhpMyAdmin\SqlParser\Components;

use PhpMyAdmin\SqlParser\Component;
use PhpMyAdmin\SqlParser\Parsers\PartitionDefinitions;
use PhpMyAdmin\SqlParser\SerializableComponent;
use PhpMyAdmin\SqlParser\Token;
use PhpMyAdmin\SqlParser\TokensList;

Expand All @@ -14,7 +14,7 @@
/**
* Parses an alter operation.
*/
final class AlterOperation implements Component
final class AlterOperation extends SerializableComponent
{
/**
* Options of this operation.
Expand Down Expand Up @@ -67,7 +67,7 @@
$ret .= $this->field . ' ';
}

$ret .= $afterFieldsOptions . TokensList::buildFromArray($this->unknown);

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

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.2

Escaped Mutant for Mutator "Concat": @@ @@ $ret .= $this->field . ' '; } - $ret .= $afterFieldsOptions . TokensList::buildFromArray($this->unknown); + $ret .= TokensList::buildFromArray($this->unknown) . $afterFieldsOptions; if (isset($this->partitions)) { $ret .= PartitionDefinitions::buildAll($this->partitions);

if (isset($this->partitions)) {
$ret .= PartitionDefinitions::buildAll($this->partitions);
Expand All @@ -75,9 +75,4 @@

return trim($ret);
}

public function __toString(): string
{
return $this->build();
}
}
9 changes: 2 additions & 7 deletions src/Components/ArrayObj.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

namespace PhpMyAdmin\SqlParser\Components;

use PhpMyAdmin\SqlParser\Component;
use PhpMyAdmin\SqlParser\SerializableComponent;

use function implode;

/**
* Parses an array.
*/
final class ArrayObj implements Component
final class ArrayObj extends SerializableComponent
{
/**
* The array that contains the unprocessed value of each token.
Expand Down Expand Up @@ -45,9 +45,4 @@ public function build(): string

return '(' . implode(', ', $this->values) . ')';
}

public function __toString(): string
{
return $this->build();
}
}
9 changes: 2 additions & 7 deletions src/Components/CaseExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

namespace PhpMyAdmin\SqlParser\Components;

use PhpMyAdmin\SqlParser\Component;
use PhpMyAdmin\SqlParser\Context;
use PhpMyAdmin\SqlParser\Parsers\Conditions;
use PhpMyAdmin\SqlParser\SerializableComponent;

use function count;

/**
* Parses a reference to a CASE expression.
*/
final class CaseExpression implements Component
final class CaseExpression extends SerializableComponent
{
/**
* The value to be compared.
Expand Down Expand Up @@ -64,7 +64,7 @@
$ret .= $this->value . ' ';
$valuesCount = count($this->compareValues);
$resultsCount = count($this->results);
for ($i = 0; $i < $valuesCount && $i < $resultsCount; ++$i) {

Check warning on line 67 in src/Components/CaseExpression.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.2

Escaped Mutant for Mutator "LogicalAnd": @@ @@ $ret .= $this->value . ' '; $valuesCount = count($this->compareValues); $resultsCount = count($this->results); - for ($i = 0; $i < $valuesCount && $i < $resultsCount; ++$i) { + for ($i = 0; $i < $valuesCount || $i < $resultsCount; ++$i) { $ret .= 'WHEN ' . $this->compareValues[$i] . ' '; $ret .= 'THEN ' . $this->results[$i] . ' '; }

Check warning on line 67 in src/Components/CaseExpression.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.2

Escaped Mutant for Mutator "LessThan": @@ @@ $ret .= $this->value . ' '; $valuesCount = count($this->compareValues); $resultsCount = count($this->results); - for ($i = 0; $i < $valuesCount && $i < $resultsCount; ++$i) { + for ($i = 0; $i < $valuesCount && $i <= $resultsCount; ++$i) { $ret .= 'WHEN ' . $this->compareValues[$i] . ' '; $ret .= 'THEN ' . $this->results[$i] . ' '; }

Check warning on line 67 in src/Components/CaseExpression.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.2

Escaped Mutant for Mutator "LessThan": @@ @@ $ret .= $this->value . ' '; $valuesCount = count($this->compareValues); $resultsCount = count($this->results); - for ($i = 0; $i < $valuesCount && $i < $resultsCount; ++$i) { + for ($i = 0; $i <= $valuesCount && $i < $resultsCount; ++$i) { $ret .= 'WHEN ' . $this->compareValues[$i] . ' '; $ret .= 'THEN ' . $this->results[$i] . ' '; }
$ret .= 'WHEN ' . $this->compareValues[$i] . ' ';
$ret .= 'THEN ' . $this->results[$i] . ' ';
}
Expand All @@ -72,7 +72,7 @@
// Syntax type 1
$valuesCount = count($this->conditions);
$resultsCount = count($this->results);
for ($i = 0; $i < $valuesCount && $i < $resultsCount; ++$i) {

Check warning on line 75 in src/Components/CaseExpression.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.2

Escaped Mutant for Mutator "LogicalAnd": @@ @@ // Syntax type 1 $valuesCount = count($this->conditions); $resultsCount = count($this->results); - for ($i = 0; $i < $valuesCount && $i < $resultsCount; ++$i) { + for ($i = 0; $i < $valuesCount || $i < $resultsCount; ++$i) { $ret .= 'WHEN ' . Conditions::buildAll($this->conditions[$i]) . ' '; $ret .= 'THEN ' . $this->results[$i] . ' '; }

Check warning on line 75 in src/Components/CaseExpression.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.2

Escaped Mutant for Mutator "LessThan": @@ @@ // Syntax type 1 $valuesCount = count($this->conditions); $resultsCount = count($this->results); - for ($i = 0; $i < $valuesCount && $i < $resultsCount; ++$i) { + for ($i = 0; $i < $valuesCount && $i <= $resultsCount; ++$i) { $ret .= 'WHEN ' . Conditions::buildAll($this->conditions[$i]) . ' '; $ret .= 'THEN ' . $this->results[$i] . ' '; }

Check warning on line 75 in src/Components/CaseExpression.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.2

Escaped Mutant for Mutator "LessThan": @@ @@ // Syntax type 1 $valuesCount = count($this->conditions); $resultsCount = count($this->results); - for ($i = 0; $i < $valuesCount && $i < $resultsCount; ++$i) { + for ($i = 0; $i <= $valuesCount && $i < $resultsCount; ++$i) { $ret .= 'WHEN ' . Conditions::buildAll($this->conditions[$i]) . ' '; $ret .= 'THEN ' . $this->results[$i] . ' '; }
$ret .= 'WHEN ' . Conditions::buildAll($this->conditions[$i]) . ' ';
$ret .= 'THEN ' . $this->results[$i] . ' ';
}
Expand All @@ -90,9 +90,4 @@

return $ret;
}

public function __toString(): string
{
return $this->build();
}
}
9 changes: 2 additions & 7 deletions src/Components/Condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

namespace PhpMyAdmin\SqlParser\Components;

use PhpMyAdmin\SqlParser\Component;
use PhpMyAdmin\SqlParser\SerializableComponent;

use function trim;

final class Condition implements Component
final class Condition extends SerializableComponent
{
/**
* Identifiers recognized.
Expand All @@ -34,16 +34,11 @@
/** @param string $expr the condition or the operator */
public function __construct(string|null $expr = null)
{
$this->expr = trim((string) $expr);

Check warning on line 37 in src/Components/Condition.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.2

Escaped Mutant for Mutator "UnwrapTrim": @@ @@ /** @PARAM string $expr the condition or the operator */ public function __construct(string|null $expr = null) { - $this->expr = trim((string) $expr); + $this->expr = (string) $expr; } public function build(): string
}

public function build(): string
{
return $this->expr;
}

public function __toString(): string
{
return $this->build();
}
}
9 changes: 2 additions & 7 deletions src/Components/CreateDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace PhpMyAdmin\SqlParser\Components;

use PhpMyAdmin\SqlParser\Component;
use PhpMyAdmin\SqlParser\Context;
use PhpMyAdmin\SqlParser\SerializableComponent;

use function trim;

Expand All @@ -14,7 +14,7 @@
*
* Used for parsing `CREATE TABLE` statement.
*/
final class CreateDefinition implements Component
final class CreateDefinition extends SerializableComponent
{
/**
* The name of the new column.
Expand Down Expand Up @@ -76,7 +76,7 @@
$tmp = '';

if ($this->isConstraint) {
$tmp .= 'CONSTRAINT ';

Check warning on line 79 in src/Components/CreateDefinition.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.2

Escaped Mutant for Mutator "Assignment": @@ @@ $tmp = ''; if ($this->isConstraint) { - $tmp .= 'CONSTRAINT '; + $tmp = 'CONSTRAINT '; } if (isset($this->name) && ($this->name !== '')) {
}

if (isset($this->name) && ($this->name !== '')) {
Expand All @@ -93,16 +93,11 @@
}

if (! empty($this->references)) {
$tmp .= 'REFERENCES ' . $this->references . ' ';

Check warning on line 96 in src/Components/CreateDefinition.php

View workflow job for this annotation

GitHub Actions / Mutation tests with PHP 8.2

Escaped Mutant for Mutator "ConcatOperandRemoval": @@ @@ } if (! empty($this->references)) { - $tmp .= 'REFERENCES ' . $this->references . ' '; + $tmp .= 'REFERENCES ' . $this->references; } $tmp .= $this->options;
}

$tmp .= $this->options;

return trim($tmp);
}

public function __toString(): string
{
return $this->build();
}
}
Loading
Loading