psalm-plugin-doctrine icon indicating copy to clipboard operation
psalm-plugin-doctrine copied to clipboard

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

Open ThomasLandauer opened this issue 3 years ago • 2 comments

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())
    

ThomasLandauer avatar Nov 13 '22 23:11 ThomasLandauer

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.

allansun avatar Dec 31 '22 02:12 allansun

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.

weirdan avatar Dec 31 '22 03:12 weirdan