Skip to content

Commit

Permalink
WIP Psalm 5.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus committed Jan 3, 2023
1 parent 3561bc5 commit 149b11a
Show file tree
Hide file tree
Showing 16 changed files with 48 additions and 55 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"squizlabs/php_codesniffer": "3.7.1",
"symfony/cache": "^5.4|^6.0",
"symfony/console": "^4.4|^5.4|^6.0",
"vimeo/psalm": "4.30.0"
"vimeo/psalm": "5.4.0"
},
"suggest": {
"symfony/console": "For helpful console commands such as SQL execution and import of files."
Expand Down
27 changes: 24 additions & 3 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,9 @@
<errorLevel type="suppress">
<!-- We're testing with invalid input here. -->
<file name="tests/Platforms/AbstractPlatformTestCase.php"/>

<!-- See https://bugs.php.net/bug.php?id=77591 -->
<referencedFunction name="db2_autocommit"/>
</errorLevel>
</InvalidArgument>
<InvalidDocblock>
Expand Down Expand Up @@ -766,6 +769,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 @@ -778,6 +782,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 @@ -793,10 +798,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);
}
}
29 changes: 3 additions & 26 deletions src/DriverManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,32 +154,9 @@ private function __construct()
*
* @param Configuration|null $config The configuration to use.
* @param EventManager|null $eventManager The event manager to use.
* @psalm-param array{
* charset?: string,
* dbname?: string,
* default_dbname?: string,
* driver?: key-of<self::DRIVER_MAP>,
* driverClass?: class-string<Driver>,
* driverOptions?: array<mixed>,
* host?: string,
* keepSlave?: bool,
* keepReplica?: bool,
* master?: OverrideParams,
* memory?: bool,
* password?: string,
* path?: string,
* pdo?: \PDO,
* platform?: Platforms\AbstractPlatform,
* port?: int,
* primary?: OverrideParams,
* replica?: array<OverrideParams>,
* sharding?: array<string,mixed>,
* slaves?: array<OverrideParams>,
* user?: string,
* wrapperClass?: class-string<T>,
* } $params
*
* @psalm-return ($params is array{wrapperClass:mixed} ? T : Connection)
* @psalm-param Params $params
*
* @psalm-return ($params is array{wrapperClass: class-string<T>} ? T : Connection)
*
* @throws Exception
*
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
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 @@ -251,14 +251,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 149b11a

Please sign in to comment.