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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Psalm 5.11.0 #5830

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.11.0"
},
"suggest": {
"symfony/console": "For helpful console commands such as SQL execution and import of files."
Expand Down
48 changes: 45 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 @@ -608,6 +610,16 @@
<!-- 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"/>

<!-- See https://github.com/doctrine/dbal/pull/3498 -->
<file name="tests/Functional/DataAccessTest.php"/>
<file name="tests/Platforms/AbstractPlatformTestCase.php"/>
<file name="tests/Platforms/DB2PlatformTest.php"/>
<file name="tests/Platforms/OraclePlatformTest.php"/>
<file name="tests/Platforms/SqlitePlatformTest.php"/>
</errorLevel>
</InvalidArgument>
<InvalidDocblock>
Expand All @@ -628,6 +640,12 @@
<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"/>
</errorLevel>
</LessSpecificReturnStatement>
<MissingConstructor>
<errorLevel type="suppress">
<!--
Expand All @@ -637,6 +655,12 @@
<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"/>
</errorLevel>
</MoreSpecificReturnType>
<NullableReturnStatement>
<errorLevel type="suppress">
<!--
Expand Down Expand Up @@ -812,6 +836,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 @@ -824,6 +849,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 @@ -839,10 +865,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. -->
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks like a bug. You shouldn't end up with NoValue while checking types from docblock. Do you know at which line it is emitted?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can give you a reproducer: https://psalm.dev/r/614cec5f0f

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I think it happens because the type is both from signature and from docblock, I'll check that

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error occurs because I first eliminate all possible values (according to the docblock) for a variable and afterwards use its value when rendering the exception message.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I know, the thing is that when a type comes from a docblock, when every type is refuted, Psalm assign the mixed type to it. It only applie the never type when the type came from signature. Here you have a signature but you actually have a more detailed type in docblock

<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);
}
}
7 changes: 6 additions & 1 deletion src/DriverManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,15 @@
* serverVersion?: string,
* sharding?: array<string,mixed>,
* slaves?: array<OverrideParams>,
* ssl_ca?: string,
* ssl_capath?: string,
* ssl_cert?: string,
* ssl_cipher?: string,
* ssl_key?: string,
* unix_socket?: string,
* url?: string,
* user?: string,
* wrapperClass?: class-string<Connection>,
* unix_socket?: string,
* }
*/
final class DriverManager
Expand Down
2 changes: 1 addition & 1 deletion src/Platforms/AbstractMySQLPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -1418,7 +1418,7 @@ public function createSchemaManager(Connection $connection): MySQLSchemaManager
}

/**
* @param list<T> $assets
* @param array<T> $assets
*
* @return array<string,T>
*
Expand Down
8 changes: 4 additions & 4 deletions src/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -2172,7 +2172,7 @@ private function buildCreateTableSQL(Table $table, bool $createIndexes, bool $cr
}

/**
* @param list<Table> $tables
* @param array<Table> $tables
*
* @return list<string>
*
Expand All @@ -2199,7 +2199,7 @@ public function getCreateTablesSQL(array $tables): array
}

/**
* @param list<Table> $tables
* @param array<Table> $tables
*
* @return list<string>
*/
Expand Down 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
11 changes: 8 additions & 3 deletions src/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,11 @@ public function fetchAllKeyValue(): array
{
$this->ensureHasKeyValue();

$data = [];
/** @var list<array{mixed, mixed}> $allRows */
$allRows = $this->fetchAllNumeric();

foreach ($this->fetchAllNumeric() as [$key, $value]) {
$data = [];
foreach ($allRows as [$key, $value]) {
$data[$key] = $value;
}

Expand Down Expand Up @@ -192,7 +194,10 @@ public function iterateKeyValue(): Traversable
{
$this->ensureHasKeyValue();

foreach ($this->iterateNumeric() as [$key, $value]) {
/** @var Traversable<mixed, array{array-key, mixed}> $iterator */
$iterator = $this->iterateNumeric();

foreach ($iterator as [$key, $value]) {
yield $key => $value;
}
}
Expand Down