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

Run static analysis jobs on PHP 8.1 #5269

Merged
merged 3 commits into from Feb 13, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/static-analysis.yml
Expand Up @@ -34,7 +34,7 @@ jobs:
strategy:
matrix:
php-version:
- "8.0"
- "8.1"

steps:
- name: "Checkout code"
Expand All @@ -60,7 +60,7 @@ jobs:
strategy:
matrix:
php-version:
- "8.0"
- "8.1"

steps:
- name: Checkout code
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Cache/ResultCacheStatement.php
Expand Up @@ -301,7 +301,7 @@ public function fetchFirstColumn(): array
* this behaviour is not guaranteed for all databases and should not be
* relied on for portable applications.
*
* @return int The number of rows.
* @return int|string The number of rows.
*/
public function rowCount()
{
Expand Down
14 changes: 7 additions & 7 deletions lib/Doctrine/DBAL/Connection.php
Expand Up @@ -799,7 +799,7 @@ private function addCriteriaCondition(
* @param array<string, mixed> $criteria Deletion criteria
* @param array<int, int|string|Type|null>|array<string, int|string|Type|null> $types Parameter types
*
* @return int The number of affected rows.
* @return int|string The number of affected rows.
*
* @throws Exception
*/
Expand Down Expand Up @@ -835,7 +835,7 @@ public function close()
*
* @param int $level The level to set.
*
* @return int
* @return int|string
*/
public function setTransactionIsolation($level)
{
Expand Down Expand Up @@ -868,7 +868,7 @@ public function getTransactionIsolation()
* @param array<string, mixed> $criteria Update criteria
* @param array<int, int|string|Type|null>|array<string, int|string|Type|null> $types Parameter types
*
* @return int The number of affected rows.
* @return int|string The number of affected rows.
*
* @throws Exception
*/
Expand Down Expand Up @@ -903,7 +903,7 @@ public function update($table, array $data, array $criteria, array $types = [])
* @param array<string, mixed> $data Column-value pairs
* @param array<int, int|string|Type|null>|array<string, int|string|Type|null> $types Parameter types
*
* @return int The number of affected rows.
* @return int|string The number of affected rows.
*
* @throws Exception
*/
Expand Down Expand Up @@ -1472,7 +1472,7 @@ public function query()
* @param array<int, mixed>|array<string, mixed> $params Statement parameters
* @param array<int, int|string|Type|null>|array<string, int|string|Type|null> $types Parameter types
*
* @return int The number of affected rows.
* @return int|string The number of affected rows.
*
* @throws Exception
*/
Expand Down Expand Up @@ -1503,7 +1503,7 @@ public function executeUpdate($sql, array $params = [], array $types = [])
* @param array<int, mixed>|array<string, mixed> $params Statement parameters
* @param array<int, int|string|Type|null>|array<string, int|string|Type|null> $types Parameter types
*
* @return int The number of affected rows.
* @return int|string The number of affected rows.
*
* @throws Exception
*/
Expand Down Expand Up @@ -1556,7 +1556,7 @@ public function executeStatement($sql, array $params = [], array $types = [])
*
* @param string $sql
*
* @return int The number of affected rows.
* @return int|string The number of affected rows.
*
* @throws Exception
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Driver/Connection.php
Expand Up @@ -43,7 +43,7 @@ public function quote($value, $type = ParameterType::STRING);
*
* @param string $sql
*
* @return int
* @return int|string
*/
public function exec($sql);

Expand Down
Expand Up @@ -9,6 +9,8 @@
use mysqli_sql_exception;
use ReflectionProperty;

use function assert;

/**
* @internal
*
Expand All @@ -18,7 +20,10 @@ final class ConnectionFailed extends MysqliException
{
public static function new(mysqli $connection): self
{
return new self($connection->connect_error, 'HY000', $connection->connect_errno);
$error = $connection->connect_error;
assert($error !== null);

return new self($error, 'HY000', $connection->connect_errno);
}

public static function upcast(mysqli_sql_exception $exception): self
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Driver/Result.php
Expand Up @@ -70,7 +70,7 @@ public function fetchFirstColumn(): array;
* some database drivers may return the number of rows returned by that query. However, this behaviour
* is not guaranteed for all drivers and should not be relied on in portable applications.
*
* @return int The number of rows.
* @return int|string The number of rows.
*/
public function rowCount();

Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Driver/Statement.php
Expand Up @@ -103,7 +103,7 @@ public function execute($params = null);
* this behaviour is not guaranteed for all databases and should not be
* relied on for portable applications.
*
* @return int The number of rows.
* @return int|string The number of rows.
*/
public function rowCount();
}
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Query/QueryBuilder.php
Expand Up @@ -201,7 +201,7 @@ public function getState()
/**
* Executes this query using the bound parameters and their types.
*
* @return ForwardCompatibility\Result|int
* @return ForwardCompatibility\Result|int|string
*
* @throws Exception
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Statement.php
Expand Up @@ -779,7 +779,7 @@ public function iterateColumn(): Traversable
/**
* Returns the number of rows affected by the last execution of this statement.
*
* @return int The number of affected rows.
* @return int|string The number of affected rows.
*/
public function rowCount()
{
Expand Down
7 changes: 7 additions & 0 deletions phpstan.neon.dist
Expand Up @@ -125,3 +125,10 @@ parameters:
message: '~^Parameter #2 \$code of class RuntimeException constructor expects int, string given\.$~'
paths:
- lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php

# Fixing the issue would cause a BC break.
# TODO: fix in 4.0.0
-
message: '~^Method Doctrine\\DBAL\\Statement::executeStatement\(\) should return int but returns int\|string\.$~'
paths:
- lib/Doctrine/DBAL/Statement.php
28 changes: 22 additions & 6 deletions psalm.xml.dist
Expand Up @@ -309,6 +309,14 @@
<file name="lib/Doctrine/DBAL/Schema/View.php"/>
</errorLevel>
</PropertyNotSetInConstructor>
<RedundantCondition>
<errorLevel type="suppress">
<!--
See https://github.com/vimeo/psalm/pull/7660
-->
<file name="lib/Doctrine/DBAL/Driver/Mysqli/Exception/ConnectionFailed.php"/>
</errorLevel>
</RedundantCondition>
<!-- This is necessary pre 4.0 -->
<RedundantCastGivenDocblockType>
<errorLevel type="suppress">
Expand Down Expand Up @@ -402,10 +410,24 @@
<file name="tests/Doctrine/Tests/DBAL/DriverManagerTest.php"/>
</errorLevel>
</InvalidArgument>
<InvalidReturnStatement>
<errorLevel type="suppress">
<!-- lastInsertId has a return type that does not match the one defined in the interface-->
<file name="lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php"/>
<!--
This issue should be fixed in 4.0
-->
<file name="lib/Doctrine/DBAL/Statement.php"/>
</errorLevel>
</InvalidReturnStatement>
<InvalidReturnType>
<errorLevel type="suppress">
<!-- lastInsertId has a return type that does not match the one defined in the interface-->
<file name="lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php"/>
<!--
This issue should be fixed in 4.0
-->
<file name="lib/Doctrine/DBAL/Statement.php"/>
</errorLevel>
</InvalidReturnType>
<InvalidScalarArgument>
Expand Down Expand Up @@ -439,11 +461,5 @@
<referencedFunction name="db2_autocommit"/>
</errorLevel>
</InvalidScalarArgument>
<InvalidReturnStatement>
<errorLevel type="suppress">
<!-- lastInsertId has a return type that does not match the one defined in the interface-->
<file name="lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php"/>
</errorLevel>
</InvalidReturnStatement>
</issueHandlers>
</psalm>