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

Suggestion: Add new Types for non-empty-string and positive-int #11748

Open
ThomasLandauer opened this issue Dec 4, 2024 · 1 comment
Open

Comments

@ThomasLandauer
Copy link
Contributor

Feature Request

What

Implement something like Types:NON_EMPTY_STRING and Types::POSITIVE_INT.

Why

Since Symfony 7.2, UserInterface::getUserIdentifier() is annotated with @return non-empty-string.

So if you're fetching that user identifier from the database, PHPStan will report something like:

Property App\Entity\User::$... type mapping mismatch: database can contain string but property expects non-empty-string.

So instead of telling everybody to just @phpstan-ignore it (e.g. at phpstan/phpstan-doctrine#204), I'm wondering if it would be possible to fix the root cause :-)

@curry684
Copy link

The root cause is not with Doctrine, as it does not take any responsibility for content validation whatsoever. As correctly pointed out in the linked issue you can always break it by directly editing the database anyway.

The true root cause is setting an entity field to non-empty-string. Your validation layers should ensure it does not get invalid content, not Doctrine or PHPStan.

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

2 participants