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

UndefinedDocblockClass: Docblock-defined class, interface or enum named UnitEnum does not exist #7703

Closed
ostrolucky opened this issue Feb 20, 2022 · 5 comments

Comments

@ostrolucky
Copy link
Contributor

ostrolucky commented Feb 20, 2022

We have no matches of "UnitEnum" in entire SncRedisBundle codebase, but psalm is reporting such issue on psalm @dev branch https://github.com/snc/SncRedisBundle/actions/runs/1871801246

Could be related to #7404 @orklah ?

@weirdan
Copy link
Collaborator

weirdan commented Feb 20, 2022

What's the return type of $container->getParameter()?

@ostrolucky
Copy link
Contributor Author

True, it contains UnitEnum https://github.com/symfony/symfony/blob/92d183eb0c1423821657f0e6d598534a9da15788/src/Symfony/Component/DependencyInjection/Container.php#L110. But there is no way around that, Symfony supports both PHP 7 and 8.1, while psalm in SncRedisBundle is running on PHP 7. Not sure why is psalm reporting issue that's actually in vendor/ and not in SncRedisBundle.

@orklah
Copy link
Collaborator

orklah commented Feb 20, 2022

You call on a method that returns an unknown class, how is that an issue in vendors?

What is Psalm supposed to do when you try to cast to string a type that is not known?

I think this is more an issue with Symfony here. What if you use Symfony in a PHP 7 codebase where you have a class named UnitEnum? (or polyfills?). The docblock they use is dangerous

I guess a stub could be added to the symfony plugin to prevent getParameter from returning UnitEnum on PHP 7 (I think something like

* @return (PHP_MAJOR_VERSION is 5|7 ? string|false : string)
may be seen as too specific to belong in the repo)

@weirdan
Copy link
Collaborator

weirdan commented Feb 20, 2022

You're attempting to call __toString() on an unknown class in some places, so the issue is technically on the SncRedisBundle's side. It'll also cause a fatal error if an enum case would actually get returned.

I think the easiest way around this is to define that interface conditionally somewhere, e.g.

if (!interface_exists(\UnitEnum::class)) {
  interface UnitEnum {}
}

@ostrolucky
Copy link
Contributor Author

Psalm error message doesn't indicate it's complaining about trying to cast an unknown class. It indicates it doesn't like mere presence of unknown type in union of return type that's defined in vendor/. Hence the confusion. Expected issue type should be PossiblyInvalidCast, or maybe even do whatever you do when psalm cannot infer the type, similarly it does with mixed? Anyways yeah I think I should suppress this issue or now in sncredis.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants