psalm / psalm-plugin-doctrine

Stubs to let Psalm understand Doctrine better
86 stars 43 forks source link

QueryBuilderSetParameter: Create page on psalm.dev to show best practice #131

Open ThomasLandauer opened 2 years ago

ThomasLandauer commented 2 years ago

I'm talking about:

QueryBuilderSetParameter - src/Repository/... - To improve performance set explicit type for objects $queryBuilder->andWhere('a.user = :user')->setParameter('user', $user);

Would it be possible to create a linked "help" page for this? Like e.g. here:

PropertyNotSetInConstructor - ... (see https://psalm.dev/074)

Cause I'd like to collect some best practices there. Some questions:

  1. At https://github.com/psalm/psalm-plugin-symfony/issues/158 there is a link to https://github.com/doctrine/orm/issues/8113. But that talks only about DateTime* (not other objects). And in Doctrine\DBAL\Types\Types this one is the only object I can see where adding the 3rd type argument to ->setParameter() does make sense. So the error message "set explicit type for objects" in fact only makes sense for DateTime?
  2. For all other cases, it's not possible to set the type, but it's recommended to switch from the entire object to some property?:
    ->andWhere('a.userId = :userId')->setParameter('userId', $user->getId())
allansun commented 1 year ago

I have the same question here.

The QueryBuilderSetParameter is quite scary when you see the title Massive performance issue, however to me it should be a 'WARNING' level instead of 'ERROR' level.

weirdan commented 1 year ago

Would it be possible to create a linked "help" page for this? Like e.g. here:

Technically you can override $link property of IssueData instance returned from toIssueData() method of the issue class. $link is declared readonly in docblock and IssueData is an internal class though, so that's not something we officially support at the moment.