Add UniqueEntity constraint field validation

Open
#556 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
php, symfony
Domain
devtools

Research direction

Start by reading the referenced RepositoryMethodCallRule.php and the Symfony UniqueEntity constraint documentation. Trace how objectManagerLoader exposes class metadata, then determine where the constraint's field arguments can be checked against the entity fields used by findBy. Done means invalid field names are reported while constraints with an overridden repository method remain ignored.

Written by the indexing model from the issue text.

Description

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.

Dominant language
PHP
Stars
678
Forks
122
Avg merge
5d 18h
Merged PRs (30d)
3

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from phpstan/phpstan-doctrine

All issues in phpstan/phpstan-doctrine

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.