-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
QueryBuilder with extra methods called on it is not reported correctly
I understand that it is hard to evaluate code like this when the things happen in separate methods. The solution may be not to analyze the query builder in this case. And the message is not very helpful because the displayed portion is similar ``` Strict comparison using === between 'SELECT e FROM…' and 'SELECT e FROM…' will always evaluate to false. ```
- Loading branch information
Showing
3 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
tests/DoctrineIntegration/ORM/data/queryBuilderExtraMethod-4.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[ | ||
] |
49 changes: 49 additions & 0 deletions
49
tests/DoctrineIntegration/ORM/data/queryBuilderExtraMethod.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\DoctrineIntegration\ORM\QueryBuilder; | ||
|
||
use Doctrine\ORM\EntityManager; | ||
use Doctrine\ORM\Query; | ||
use Doctrine\ORM\QueryBuilder; | ||
use PHPStan\DoctrineIntegration\ORM\CustomRepositoryUsage\MyEntity; | ||
|
||
class Foo | ||
{ | ||
|
||
/** | ||
* @var EntityManager | ||
*/ | ||
private $entityManager; | ||
|
||
public function __construct(EntityManager $entityManager) | ||
{ | ||
$this->entityManager = $entityManager; | ||
} | ||
|
||
public function doFoo(): Query | ||
{ | ||
$queryBuilder = $this->entityManager->createQueryBuilder() | ||
->select('e') | ||
->from(MyEntity::class, 'e'); | ||
|
||
// @todo it works when the extra where is here | ||
//$queryBuilder->andWhere('e.id != :excludedId'); | ||
|
||
// but it does not work when the where is added in extra method | ||
$this->addExtraCondition($queryBuilder); | ||
|
||
$query = $queryBuilder->getQuery(); | ||
|
||
$expectedDql = 'SELECT e FROM PHPStan\DoctrineIntegration\ORM\CustomRepositoryUsage\MyEntity e WHERE e.id != :excludedId'; | ||
$query->getDQL() === $expectedDql; | ||
$queryBuilder->getDQL() === $expectedDql; | ||
|
||
return $query; | ||
} | ||
|
||
private function addExtraCondition(QueryBuilder $queryBuilder): void | ||
{ | ||
$queryBuilder->andWhere('e.id != :excludedId'); | ||
} | ||
|
||
} |