From 487b00fbcb2a607bd12bb78fbc27739216ec4626 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Fri, 1 May 2020 08:15:36 +0200 Subject: [PATCH] Describe return type accurately This return type is conditional to $params['wrapperClass']. Luckily, recent versions of Psalm allow documenting it properly. See https://github.com/vimeo/psalm/issues/3277 Note that phpstan is not able to understand this yet, but still attempts to, hence the extra ignore rules. --- composer.json | 2 +- composer.lock | 12 ++++++------ lib/Doctrine/DBAL/DriverManager.php | 10 +++++++--- phpstan.neon.dist | 7 +++++++ 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/composer.json b/composer.json index 09263687d3d..68b7fe623be 100644 --- a/composer.json +++ b/composer.json @@ -45,7 +45,7 @@ "phpunit/phpunit": "^8.5.5", "psalm/plugin-phpunit": "^0.10.0", "symfony/console": "^2.0.5|^3.0|^4.0|^5.0", - "vimeo/psalm": "^3.11" + "vimeo/psalm": "^3.11.4" }, "suggest": { "symfony/console": "For helpful console commands such as SQL execution and import of files." diff --git a/composer.lock b/composer.lock index 3329a978cae..37114014b9a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9157c6d35dd39f5399592fd91126fa07", + "content-hash": "0372454a0ee2de4c2051cc13cbb23b72", "packages": [ { "name": "doctrine/cache", @@ -2995,16 +2995,16 @@ }, { "name": "vimeo/psalm", - "version": "3.11.2", + "version": "3.11.4", "source": { "type": "git", "url": "https://github.com/vimeo/psalm.git", - "reference": "d470903722cfcbc1cd04744c5491d3e6d13ec3d9" + "reference": "58e1d8e68e5098bf4fbfdfb420c38d563f882549" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/vimeo/psalm/zipball/d470903722cfcbc1cd04744c5491d3e6d13ec3d9", - "reference": "d470903722cfcbc1cd04744c5491d3e6d13ec3d9", + "url": "https://api.github.com/repos/vimeo/psalm/zipball/58e1d8e68e5098bf4fbfdfb420c38d563f882549", + "reference": "58e1d8e68e5098bf4fbfdfb420c38d563f882549", "shasum": "" }, "require": { @@ -3089,7 +3089,7 @@ "inspection", "php" ], - "time": "2020-04-13T12:47:11+00:00" + "time": "2020-05-11T13:39:25+00:00" }, { "name": "webmozart/assert", diff --git a/lib/Doctrine/DBAL/DriverManager.php b/lib/Doctrine/DBAL/DriverManager.php index 95cb27c29d7..d3ed63a7f39 100644 --- a/lib/Doctrine/DBAL/DriverManager.php +++ b/lib/Doctrine/DBAL/DriverManager.php @@ -115,11 +115,15 @@ private function __construct() * driverClass: * The driver class to use. * - * @param mixed[] $params The parameters. - * @param Configuration|null $config The configuration to use. - * @param EventManager|null $eventManager The event manager to use. + * @param array{wrapperClass?: class-string} $params + * @param Configuration|null $config The configuration to use. + * @param EventManager|null $eventManager The event manager to use. * * @throws DBALException + * + * @phpstan-param mixed[] $params + * @psalm-return ($params is array{wrapperClass:mixed} ? T : Connection) + * @template T of Connection */ public static function getConnection( array $params, diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 70544cbf7ec..40bc84910a1 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -83,3 +83,10 @@ parameters: # Needs Generics - '~Method Doctrine\\DBAL\\Schema\\SchemaDiff::getNewTablesSortedByDependencies\(\) should return array but returns array.~' + + # Caused by phpdoc annotations intended for Psalm + - + message: '~Unable to resolve the template type T in call to method static method Doctrine\\DBAL\\DriverManager::getConnection\(\)~' + paths: + - %currentWorkingDirectory%/lib/Doctrine/DBAL/Id/TableGenerator.php + - %currentWorkingDirectory%/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php