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

Feature request: field validation when using matching()/Criteria #470

Open
Firehed opened this issue Sep 13, 2023 · 0 comments
Open

Feature request: field validation when using matching()/Criteria #470

Firehed opened this issue Sep 13, 2023 · 0 comments

Comments

@Firehed
Copy link

Firehed commented Sep 13, 2023

Right now, the phpstan-doctrine extension is able to validate that common loading patterns (findBy and friends) are only passed mapped columns, which is awesome and has saved me from more errors than I'd care to admit!

Today, I noticed that if you need to perform a more advanced query using Criteria (e.g. fields greater/less than some value), that same validation doesn't appear to take place - I can mistype a field name and get a runtime error without advance warning from the plugin. This appears to be the case with or without the "advanced" configuration (objectManagerLoader) being performed.

I expect this is a low-priority, low-volume scenario - but it would be really great if somehow these mappings could get tracked all the way through and make it into analysis.

Rough example (setup excluded):

#[Entity]
class MyModel
{
  #[Column]
  public ?DateTime $dueAt;
}

// ...

use Doctrine\Common\Collections\Criteria;
$expr = Criteria::expr();
$criteria = Criteria::create()->where($expr->lt('due', new DateTime())); // note field name mismatch
assert($em instanceof Doctrine\ORM\EntityManagerInterface);
$models = $em->getRepository(MyModel::class)->matching($criteria)->toArray();

I expect based on type information, the error would probably have to appear on the matching() call rather than in the criteria setup (since criteria on its own is basically a context-free WHERE clause); that would still be more than sufficient to get advance warning of a problem :)

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

1 participant