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

PHPStan 1.0.2 #4943

Merged
merged 1 commit into from
Nov 4, 2021
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"require-dev": {
"doctrine/coding-standard": "9.0.0",
"jetbrains/phpstorm-stubs": "2021.1",
"phpstan/phpstan": "0.12.99",
"phpstan/phpstan": "1.0.2",
"phpunit/phpunit": "^7.5.20|^8.5|9.5.10",
"psalm/plugin-phpunit": "0.16.1",
"squizlabs/php_codesniffer": "3.6.1",
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -1641,7 +1641,7 @@ public function errorInfo()
*
* @param string|null $name Name of the sequence object from which the ID should be returned.
*
* @return string A string representation of the last inserted ID.
* @return string|int|false A string representation of the last inserted ID.
*/
public function lastInsertId($name = null)
{
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/DBAL/DBALException.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public static function driverExceptionDuringQuery(Driver $driver, Throwable $dri

$msg .= ":\n\n" . $driverEx->getMessage();

return static::wrapException($driver, $driverEx, $msg);
return self::wrapException($driver, $driverEx, $msg);
derrabus marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand All @@ -166,7 +166,7 @@ public static function driverExceptionDuringQuery(Driver $driver, Throwable $dri
*/
public static function driverException(Driver $driver, Throwable $driverEx)
{
return static::wrapException($driver, $driverEx, 'An exception occurred in driver: ' . $driverEx->getMessage());
return self::wrapException($driver, $driverEx, 'An exception occurred in driver: ' . $driverEx->getMessage());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Driver/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function exec($sql);
*
* @param string|null $name
*
* @return string
* @return string|int|false
*/
public function lastInsertId($name = null);

Expand Down
4 changes: 4 additions & 0 deletions lib/Doctrine/DBAL/Driver/PDOConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ public function quote($value, $type = ParameterType::STRING)

/**
* {@inheritdoc}
*
* @param string|null $name
*
* @return string|int|false
*/
#[ReturnTypeWillChange]
public function lastInsertId($name = null)
Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/DBAL/SQLParserUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,13 @@ public static function expandListParameters($query, $params, $types)

foreach ($paramPos as $pos => $paramName) {
$paramLen = strlen($paramName) + 1;
$value = static::extractParam($paramName, $params, true);
$value = self::extractParam($paramName, $params, true);

if (! isset($arrayPositions[$paramName]) && ! isset($arrayPositions[':' . $paramName])) {
$pos += $queryOffset;
$queryOffset -= $paramLen - 1;
$paramsOrd[] = $value;
$typesOrd[] = static::extractParam($paramName, $types, false, ParameterType::STRING);
$typesOrd[] = self::extractParam($paramName, $types, false, ParameterType::STRING);
$query = substr($query, 0, $pos) . '?' . substr($query, $pos + $paramLen);

continue;
Expand All @@ -241,7 +241,7 @@ public static function expandListParameters($query, $params, $types)

foreach ($value as $val) {
$paramsOrd[] = $val;
$typesOrd[] = static::extractParam($paramName, $types, false) - Connection::ARRAY_PARAM_OFFSET;
$typesOrd[] = self::extractParam($paramName, $types, false) - Connection::ARRAY_PARAM_OFFSET;
}

$pos += $queryOffset;
Expand Down
7 changes: 0 additions & 7 deletions lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Doctrine\DBAL\Driver\Exception;
use Doctrine\DBAL\Platforms\SQLServerPlatform;
use Doctrine\DBAL\Types\Type;
use PDOException;
use Throwable;

use function assert;
Expand Down Expand Up @@ -252,12 +251,6 @@ public function listTableIndexes($table)

try {
$tableIndexes = $this->_conn->fetchAllAssociative($sql);
} catch (PDOException $e) {
if ($e->getCode() === 'IMSSP') {
return [];
}

throw $e;
} catch (DBALException $e) {
if (strpos($e->getMessage(), 'SQLSTATE [01000, 15472]') === 0) {
return [];
Expand Down
28 changes: 14 additions & 14 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ parameters:
# removing it would be BC break
- '~^Constructor of class Doctrine\\DBAL\\Schema\\Table has an unused parameter \$idGeneratorType\.\z~'

# changing these would be a BC break, to be done in next major
- '~^Return type \(int\|false\) of method Doctrine\\DBAL\\Driver\\OCI8\\OCI8Connection\:\:lastInsertId\(\) should be compatible with return type \(string\) of method Doctrine\\DBAL\\Driver\\Connection::lastInsertId\(\)~'

# https://github.com/doctrine/dbal/pull/3836
- '~^Parameter #2 \$registeredAliases of static method Doctrine\\DBAL\\Query\\QueryException::nonUniqueAlias\(\) expects array<string>, array<int, int\|string> given\.\z~'

Expand Down Expand Up @@ -61,12 +58,6 @@ parameters:
paths:
- lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php

# Fixing the issue may cause a BC break.
-
message: '~^Method Doctrine\\DBAL\\Driver\\Mysqli\\MysqliConnection::lastInsertId\(\) should return string but returns int\|string\.$~'
paths:
- lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php

# This is deprecated code. Fixing the issue may cause a BC break.
# TODO: remove in 3.0.0
-
Expand All @@ -75,7 +66,7 @@ parameters:
- lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php

-
message: '~Method Doctrine\\DBAL\\Driver\\PDOSqlsrv\\Connection\:\:lastInsertId\(\) should return string but returns int\|string\|false\|null\.~'
message: '~Method Doctrine\\DBAL\\Driver\\PDOSqlsrv\\Connection\:\:lastInsertId\(\) should return int\|string\|false but returns int\|string\|false\|null\.~'
paths:
- lib/Doctrine/DBAL/Driver/PDOSqlsrv/Connection.php

Expand All @@ -96,9 +87,19 @@ parameters:
paths:
- lib/Doctrine/DBAL/Connection.php

# https://github.com/phpstan/phpstan/issues/5608
# PHPStan fails to parse this type alias which is meant for Psalm only.
-
message: '~^Invalid type definition detected in type alias (Override)?Params\.$~'
paths:
- lib/Doctrine/DBAL/DriverManager.php

-
message: '~Template type T of method Doctrine\\DBAL\\DriverManager::getConnection\(\) is not referenced in a parameter\.~'
paths:
- lib/Doctrine/DBAL/DriverManager.php

-
message: '~^Circular definition detected in type alias (Override)?Params\.$~'
message: '~Method Doctrine\\DBAL\\DriverManager::createDriver\(\) should return Doctrine\\DBAL\\Driver but returns object\.~'
morozov marked this conversation as resolved.
Show resolved Hide resolved
paths:
- lib/Doctrine/DBAL/DriverManager.php

Expand All @@ -120,8 +121,7 @@ parameters:
paths:
- lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php

# https://github.com/phpstan/phpstan-src/pull/700
-
message: '~^Parameter #2 \$count of function array_fill expects int<0, max>, int given\.$~'
message: '~Method Doctrine\\DBAL\\Driver\\Mysqli\\MysqliStatement::rowCount\(\) should return int but returns int\|string\.~'
Copy link
Member Author

@derrabus derrabus Nov 1, 2021

Choose a reason for hiding this comment

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

@morozov This error seems to be raised because of the stub you contributed in phpstan/phpstan-src#700.

The mysqli_stmt::$affected_rows property is documented as int|string which is also what the documentation on php.net says. The documentation does not say in which cases we can expect a string here, but my guess is that this happens if the number of affected rows is larger than PHP_INT_MAX.

However, this also applies to mysqli_stmt::$num_rows which your stub documents as 0|positive-int.

Copy link
Member

Choose a reason for hiding this comment

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

So the stub probably should be 0|positive-int|string, as well as the return type in the DBAL driver.

Copy link
Member

@morozov morozov Nov 2, 2021

Choose a reason for hiding this comment

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

I.e. we also need to change the @return annotation on (Statement|Result)::rowCount() from int to int|string because it will return a string if the value is greater than PHP_INT_MAX.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a bit of a problem because on 3.1.x, we already have an int return type declaration.

Copy link
Member

Choose a reason for hiding this comment

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

I see. Then I think it's acceptable. Unlike the discussion in doctrine/orm#8963 (comment), updating or deleting a number of rows larger than PHP_INT_MAX is close to impossible.

paths:
- lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/DBAL/Functional/WriteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ public function testDeleteWhereIsNull(): void
* Returns the ID of the last inserted row or skips the test if the currently used driver
* doesn't support this feature
*
* @return string|false
* @return string|int|false
*
* @throws Exception
*/
Expand Down