-
Notifications
You must be signed in to change notification settings - Fork 93
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
Support Symfony Validator #365
Comments
Please show a piece of code where you're experiencing this error. |
Yes, the code of my custom validator
And the Symfony constraint
Then when I run the PhpStan with the Symfony extension enabled, I got these errors for each custom validator
Thanks, |
i have the same issue when i update phpstan/phpstan-symfony from 1.3.2 to 1.3.4
The corresponding code is:
$validator is autoinjected by My phpstan/phpstan version is 1.10.39 With phpstan/phpstan-symfony 1.3.2 i get no error, only when i update to 1.3.4 |
As explained in https://symfony.com/doc/current/validation/custom_constraint.html#creating-the-validator-itself, you should add a guard to ensure the constraint is the expected type: if (!$constraint instanceof YourConstraint) {
throw new UnexpectedTypeException($constraint, YourConstraint::class);
} Now PHPStan should treat the constraint as your constraint class below the guard! |
Situation could be improved with generics the same way security Voters work but that’s up to Symfony to decide. |
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. |
Hi,
I have plenty of errors due to Symfony Validor 👍
Seems that phpStan does not understand this...
Is there something to configure ?
Thanks,
The text was updated successfully, but these errors were encountered: