phpstan/phpstan-doctrine

Add UniqueEntity constraint field validation

VincentLanglet opened this issue · 0 comments

Symfony provides a UniqueEntity annotation
https://symfony.com/doc/current/reference/constraints/UniqueEntity.html

The first arguments need to be entity fields, which will be use by a findBy call (by default).
So a rule could be implemented, similar to

class RepositoryMethodCallRule implements Rule

in order to check that all field names passed exist.

The repository method can be overriden in the constraint to use something else than findBy,
as a first step we could ignore constraint with an overridden method.

@ondrejmirtes I know it's a Symfony constraint, but since it requires objectManagerLoader to have class metadata I think it's more an issue for phpstan-doctrine or phpstan-symfony.