Skip to content

Commit

Permalink
WIP Psalm 5.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus committed Mar 13, 2023
1 parent 9058614 commit 57ee6f6
Show file tree
Hide file tree
Showing 17 changed files with 75 additions and 33 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"squizlabs/php_codesniffer": "3.7.2",
"symfony/cache": "^5.4|^6.0",
"symfony/console": "^4.4|^5.4|^6.0",
"vimeo/psalm": "4.30.0"
"vimeo/psalm": "5.8.0"
},
"suggest": {
"symfony/console": "For helpful console commands such as SQL execution and import of files."
Expand Down
53 changes: 50 additions & 3 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
findUnusedBaselineEntry="false"
findUnusedCode="false"
>
<projectFiles>
<directory name="src" />
Expand Down Expand Up @@ -607,6 +609,9 @@
<!-- We're testing with invalid input here. -->
<file name="tests/Functional/LegacyAPITest.php"/>
<file name="tests/Platforms/AbstractPlatformTestCase.php"/>

<!-- See https://bugs.php.net/bug.php?id=77591 -->
<referencedFunction name="db2_autocommit"/>
</errorLevel>
</InvalidArgument>
<InvalidDocblock>
Expand All @@ -627,6 +632,18 @@
<file name="src/Driver/PDO/Exception.php"/>
</errorLevel>
</InvalidPropertyAssignmentValue>
<LessSpecificReturnStatement>
<errorLevel type="suppress">
<!-- Psalm does not understand the polymorphism of the PDO::fetch() and fetchAll() methods -->
<file name="src/Driver/PDO/Result.php"/>

<!-- Psalm does not understand the type of the result set of a given SQL query. -->
<file name="src/Schema/AbstractSchemaManager.php"/>
<file name="src/Schema/OracleSchemaManager.php"/>
<file name="src/Schema/PostgreSQLSchemaManager.php"/>
<file name="src/Schema/SQLServerSchemaManager.php"/>
</errorLevel>
</LessSpecificReturnStatement>
<MissingConstructor>
<errorLevel type="suppress">
<!--
Expand All @@ -636,6 +653,18 @@
<file name="src/Schema/SchemaConfig.php"/>
</errorLevel>
</MissingConstructor>
<MoreSpecificReturnType>
<errorLevel type="suppress">
<!-- Psalm does not understand the polymorphism of the PDO::fetch() and fetchAll() methods -->
<file name="src/Driver/PDO/Result.php"/>

<!-- Psalm does not understand the type of the result set of a given SQL query. -->
<file name="src/Schema/AbstractSchemaManager.php"/>
<file name="src/Schema/OracleSchemaManager.php"/>
<file name="src/Schema/PostgreSQLSchemaManager.php"/>
<file name="src/Schema/SQLServerSchemaManager.php"/>
</errorLevel>
</MoreSpecificReturnType>
<NullableReturnStatement>
<errorLevel type="suppress">
<!--
Expand Down Expand Up @@ -811,6 +840,7 @@
This issue should be fixed in 4.0
-->
<file name="src/Connection.php"/>
<file name="src/Driver/Mysqli/Result.php"/>
<file name="src/Statement.php"/>
<file name="src/Query/QueryBuilder.php"/>
</errorLevel>
Expand All @@ -823,6 +853,7 @@
This issue should be fixed in 4.0
-->
<file name="src/Connection.php"/>
<file name="src/Driver/Mysqli/Result.php"/>
<file name="src/Statement.php"/>
<file name="src/Query/QueryBuilder.php"/>
</errorLevel>
Expand All @@ -838,10 +869,26 @@

<!-- See https://github.com/doctrine/dbal/pull/3574 -->
<file name="tests/Query/Expression/ExpressionBuilderTest.php"/>

<!-- See https://bugs.php.net/bug.php?id=77591 -->
<referencedFunction name="db2_autocommit"/>
</errorLevel>
</InvalidScalarArgument>
<MethodSignatureMustProvideReturnType>
<errorLevel type="suppress">
<!-- https://github.com/vimeo/psalm/issues/8557 -->
<file name="src/Query/Expression/CompositeExpression.php"/>
<file name="src/Query/QueryBuilder.php"/>
</errorLevel>
</MethodSignatureMustProvideReturnType>
<NoValue>
<errorLevel type="suppress">
<!-- We're checking for invalid input. -->
<file name="src/Platforms/AbstractPlatform.php"/>
<file name="src/Platforms/SQLServerPlatform.php"/>
</errorLevel>
</NoValue>
<UnsupportedReferenceUsage>
<errorLevel type="suppress">
<file name="src/Driver/SQLSrv/Statement.php"/>
</errorLevel>
</UnsupportedReferenceUsage>
</issueHandlers>
</psalm>
2 changes: 1 addition & 1 deletion src/Driver/IBMDB2/Exception/CannotCopyStreamToStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
final class CannotCopyStreamToStream extends AbstractException
{
/** @psalm-param array{message: string}|null $error */
/** @psalm-param array{message: string, ...mixed}|null $error */
public static function new(?array $error): self
{
$message = 'Could not copy source stream to temporary file';
Expand Down
2 changes: 1 addition & 1 deletion src/Driver/IBMDB2/Exception/CannotCreateTemporaryFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
final class CannotCreateTemporaryFile extends AbstractException
{
/** @psalm-param array{message: string}|null $error */
/** @psalm-param array{message: string, ...mixed}|null $error */
public static function new(?array $error): self
{
$message = 'Could not create temporary file';
Expand Down
2 changes: 1 addition & 1 deletion src/Driver/IBMDB2/Exception/PrepareFailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
final class PrepareFailed extends AbstractException
{
/** @psalm-param array{message: string}|null $error */
/** @psalm-param array{message: string, ...mixed}|null $error */
public static function new(?array $error): self
{
if ($error === null) {
Expand Down
2 changes: 1 addition & 1 deletion src/Driver/Mysqli/Exception/ConnectionError.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ public static function upcast(mysqli_sql_exception $exception): self
$p = new ReflectionProperty(mysqli_sql_exception::class, 'sqlstate');
$p->setAccessible(true);

return new self($exception->getMessage(), $p->getValue($exception), (int) $exception->getCode(), $exception);
return new self($exception->getMessage(), $p->getValue($exception), $exception->getCode(), $exception);
}
}
2 changes: 1 addition & 1 deletion src/Driver/Mysqli/Exception/ConnectionFailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ public static function upcast(mysqli_sql_exception $exception): self
$p = new ReflectionProperty(mysqli_sql_exception::class, 'sqlstate');
$p->setAccessible(true);

return new self($exception->getMessage(), $p->getValue($exception), (int) $exception->getCode(), $exception);
return new self($exception->getMessage(), $p->getValue($exception), $exception->getCode(), $exception);
}
}
2 changes: 1 addition & 1 deletion src/Driver/Mysqli/Exception/InvalidCharset.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static function upcast(mysqli_sql_exception $exception, string $charset):
return new self(
sprintf('Failed to set charset "%s": %s', $charset, $exception->getMessage()),
$p->getValue($exception),
(int) $exception->getCode(),
$exception->getCode(),
$exception,
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Driver/Mysqli/Exception/StatementError.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ public static function upcast(mysqli_sql_exception $exception): self
$p = new ReflectionProperty(mysqli_sql_exception::class, 'sqlstate');
$p->setAccessible(true);

return new self($exception->getMessage(), $p->getValue($exception), (int) $exception->getCode(), $exception);
return new self($exception->getMessage(), $p->getValue($exception), $exception->getCode(), $exception);
}
}
4 changes: 2 additions & 2 deletions src/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -2840,7 +2840,7 @@ protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff)
return $sql;
}

/** @return string[] */
/** @return list<string> */
protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff)
{
$sql = [];
Expand Down Expand Up @@ -2888,7 +2888,7 @@ protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff)
* @param Index $index The definition of the index to rename to.
* @param string $tableName The table to rename the given index on.
*
* @return string[] The sequence of SQL statements for renaming the given index.
* @return list<string> The sequence of SQL statements for renaming the given index.
*/
protected function getRenameIndexSQL($oldIndexName, Index $index, $tableName)
{
Expand Down
14 changes: 6 additions & 8 deletions src/Schema/TableDiff.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class TableDiff
*
* @internal Use {@see getAddedForeignKeys()} instead.
*
* @var ForeignKeyConstraint[]
* @var list<ForeignKeyConstraint>
*/
public $addedForeignKeys = [];

Expand All @@ -114,7 +114,7 @@ class TableDiff
*
* @internal Use {@see getModifiedForeignKeys()} instead.
*
* @var ForeignKeyConstraint[]
* @var list<ForeignKeyConstraint>
*/
public $changedForeignKeys = [];

Expand All @@ -123,7 +123,7 @@ class TableDiff
*
* @internal Use {@see getDroppedForeignKeys()} instead.
*
* @var (ForeignKeyConstraint|string)[]
* @var list<ForeignKeyConstraint|string>
*/
public $removedForeignKeys = [];

Expand Down Expand Up @@ -333,12 +333,10 @@ public function getDroppedForeignKeys(): array
*/
public function unsetDroppedForeignKey($foreignKey): void
{
$this->removedForeignKeys = array_filter(
$this->removedForeignKeys = array_values(array_filter(
$this->removedForeignKeys,
static function ($removedForeignKey) use ($foreignKey): bool {
return $removedForeignKey !== $foreignKey;
},
);
static fn ($removedForeignKey): bool => $removedForeignKey !== $foreignKey,
));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ class ConnectionTest extends TestCase
{
use VerifyDeprecations;

private Connection $connection;

private const CONNECTION_PARAMS = [
'driver' => 'pdo_mysql',
'host' => 'localhost',
Expand All @@ -47,6 +45,8 @@ class ConnectionTest extends TestCase
'port' => 1234,
];

private Connection $connection;

protected function setUp(): void
{
$this->connection = DriverManager::getConnection(self::CONNECTION_PARAMS);
Expand Down
5 changes: 1 addition & 4 deletions tests/Functional/BlobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ public function testInsertNull(): void
]);

self::assertEquals(1, $ret);

[$clobValue, $blobValue] = $this->fetchRow();
self::assertNull($clobValue);
self::assertNull($blobValue);
self::assertSame([null, null], $this->fetchRow());
}

public function testInsertProcessesStream(): void
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/Platform/LengthExpressionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function testLengthExpression(string $value, int $expected, bool $isMulti
self::assertEquals($expected, $this->connection->fetchOne($query, [$value]));
}

/** @return iterable<string,array{string,int}> */
/** @return iterable<string, array{string, int, bool}> */
public static function expressionProvider(): iterable
{
yield '1-byte' => ['Hello, world!', 13, false];
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/Platform/RenameColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function testColumnPositionRetainedAfterRenaming(string $columnName, stri
self::assertSame([strtolower($newColumnName), 'c2'], array_keys($table->getColumns()));
}

/** @return iterable<array{string}> */
/** @return iterable<array{string, string}> */
public static function columnNameProvider(): iterable
{
yield ['c1', 'c1_x'];
Expand Down
4 changes: 2 additions & 2 deletions tests/Functional/Schema/PostgreSQLSchemaManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,14 @@ public function testListForeignKeys(): void
$fkOptions = ['SET NULL', 'SET DEFAULT', 'NO ACTION', 'CASCADE', 'RESTRICT'];
$foreignKeys = [];
$fkTable = $this->getTestTable('test_create_fk1');
for ($i = 0; $i < count($fkOptions); $i++) {
foreach ($fkOptions as $i => $currentOption) {
$fkTable->addColumn('foreign_key_test' . $i, 'integer');
$foreignKeys[] = new ForeignKeyConstraint(
['foreign_key_test' . $i],
'test_create_fk2',
['id'],
'foreign_key_test' . $i . '_fk',
['onDelete' => $fkOptions[$i]],
['onDelete' => $currentOption],
);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Query/Expression/ExpressionBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public function testIsNotNull(): void

public function testIn(): void
{
self::assertEquals('u.groups IN (1, 3, 4, 7)', $this->expr->in('u.groups', [1, 3, 4, 7]));
self::assertEquals('u.groups IN (1, 3, 4, 7)', $this->expr->in('u.groups', ['1', '3', '4', '7']));
}

public function testInWithPlaceholder(): void
Expand All @@ -237,7 +237,7 @@ public function testInWithPlaceholder(): void

public function testNotIn(): void
{
self::assertEquals('u.groups NOT IN (1, 3, 4, 7)', $this->expr->notIn('u.groups', [1, 3, 4, 7]));
self::assertEquals('u.groups NOT IN (1, 3, 4, 7)', $this->expr->notIn('u.groups', ['1', '3', '4', '7']));
}

public function testNotInWithPlaceholder(): void
Expand Down

0 comments on commit 57ee6f6

Please sign in to comment.