From c6e163f1bcad14d57eec7beaf2ce42ffe1c802dc Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Mon, 1 Nov 2021 11:46:22 +0100 Subject: [PATCH] PHPStan 1.0.0 Signed-off-by: Alexander M. Turek --- composer.json | 2 +- lib/Doctrine/DBAL/DBALException.php | 4 ++-- lib/Doctrine/DBAL/SQLParserUtils.php | 6 +++--- phpstan.neon.dist | 27 +++++++++++++++++++++++---- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/composer.json b/composer.json index af2b84dfd62..49ba3f29ddc 100644 --- a/composer.json +++ b/composer.json @@ -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.0", "phpunit/phpunit": "^7.5.20|^8.5|9.5.10", "psalm/plugin-phpunit": "0.16.1", "squizlabs/php_codesniffer": "3.6.1", diff --git a/lib/Doctrine/DBAL/DBALException.php b/lib/Doctrine/DBAL/DBALException.php index b9a33cf1f70..2de5824f027 100644 --- a/lib/Doctrine/DBAL/DBALException.php +++ b/lib/Doctrine/DBAL/DBALException.php @@ -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); } /** @@ -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()); } /** diff --git a/lib/Doctrine/DBAL/SQLParserUtils.php b/lib/Doctrine/DBAL/SQLParserUtils.php index 604904dfce2..e31f3313756 100644 --- a/lib/Doctrine/DBAL/SQLParserUtils.php +++ b/lib/Doctrine/DBAL/SQLParserUtils.php @@ -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; @@ -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; diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 0b72e5abc4d..f43ece13daf 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -79,6 +79,11 @@ parameters: paths: - lib/Doctrine/DBAL/Driver/PDOSqlsrv/Connection.php + - + message: '~Method Doctrine\\DBAL\\Driver\\PDOConnection\:\:lastInsertId\(\) should return string but returns string\|false\.~' + paths: + - lib/Doctrine/DBAL/Driver/PDOConnection.php + - message: '~Return type \(Doctrine\\DBAL\\Portability\\Statement\) of method Doctrine\\DBAL\\Portability\\Connection::prepare\(\) should be compatible with return type \(Doctrine\\DBAL\\Statement\) of method Doctrine\\DBAL\\Connection::prepare\(\)~' paths: @@ -96,9 +101,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: '~^Circular definition detected in type alias (Override)?Params\.$~' + message: '~Template type T of method Doctrine\\DBAL\\DriverManager::getConnection\(\) is not referenced in a parameter\.~' + paths: + - lib/Doctrine/DBAL/DriverManager.php + + - + message: '~Method Doctrine\\DBAL\\DriverManager::createDriver\(\) should return Doctrine\\DBAL\\Driver but returns object\.~' paths: - lib/Doctrine/DBAL/DriverManager.php @@ -120,8 +135,12 @@ 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\.~' paths: - lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php + + - + message: '~Dead catch - PDOException is never thrown in the try block\.~' + paths: + - lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php