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

PHPStan error: "Unable to resolve the template type T" in DriverManager #4264

Closed
pkruithof opened this issue Sep 10, 2020 · 8 comments
Closed

Comments

@pkruithof
Copy link
Contributor

pkruithof commented Sep 10, 2020

Continued from #3977 (comment)

Q A
Version 2.10.x

Support Question

As discussed in #3977, the annotations for the DriverManager class now result in a PHPStan error.

* @param array{wrapperClass?: class-string<T>} $params
* @param Configuration|null $config The configuration to use.
* @param EventManager|null $eventManager The event manager to use.
*
* @throws Exception
*
* @phpstan-param mixed[] $params
* @psalm-return ($params is array{wrapperClass:mixed} ? T : Connection)
* @template T of Connection
*/
public static function getConnection(
array $params,
?Configuration $config = null,
?EventManager $eventManager = null
): Connection {

This error is currently ignored by this repo:

dbal/phpstan.neon.dist

Lines 101 to 106 in f97ee94

# 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

However the same error is reported in projects that use dbal (when they use the DriverManager of course), which I think should not happen. Here is the trimmed down version of the error case: https://phpstan.org/r/6ffb80b4-bb00-419d-bc98-887488e1c36b

The PHPStan author suggested a possible solution, which does not work unfortunately. So there is more investigation needed as to why this happens, and how to resolve it.

@pkruithof pkruithof mentioned this issue Sep 10, 2020
16 tasks
@muglug
Copy link

muglug commented Sep 10, 2020

In my opinion this sort of error should not be shown to users of a static analysis tool — it’s rarely ever the users’ fault.

@ondrejmirtes
Copy link
Contributor

FYI the annoying message about "unable to resolve template type" will no longer show up in these cases (because the template type is not present in the return type used by PHPStan): https://phpstan.org/r/3273047f-31d7-42bb-8763-357e10553eb5

Thanks to commit: phpstan/phpstan-src@a5f9f0c

@greg0ire
Copy link
Member

@pkruithof can you please try updating and report back?

@greg0ire
Copy link
Member

Thanks @ondrejmirtes BTW :)

@pkruithof
Copy link
Contributor Author

@pkruithof can you please try updating and report back?

Unfortunately I cannot remember where I encountered this, and I can't find any references in our repositories to it anymore. 😅

I'll close the issue for now as I believe it should be resolved. Should I encounter it again I can always open a new ticket.

@pkruithof
Copy link
Contributor Author

@greg0ire last night phpstan was updated by Dependabot in the project that had this issue, and where we ignored the error to fix it. The ignore is no longer needed so I can confirm that the issue is indeed fixed.

@greg0ire
Copy link
Member

Great, thanks a lot!

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants