phpstan-doctrine icon indicating copy to clipboard operation
phpstan-doctrine copied to clipboard

Add UniqueEntity constraint field validation

Open VincentLanglet opened this issue 3 months ago • 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 https://github.com/phpstan/phpstan-doctrine/blob/0871900872abde0d93e4bbd8c681a9985bcd927e/src/Rules/Doctrine/ORM/RepositoryMethodCallRule.php#L19 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.

VincentLanglet avatar Mar 27 '24 10:03 VincentLanglet