Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/Type/Doctrine/ArgumentsProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PHPStan\Rules\Doctrine\ORM\DynamicQueryBuilderArgumentException;
use PHPStan\Type\Doctrine\QueryBuilder\Expr\ExprType;
use function count;
use function in_array;
use function strpos;

/** @api */
Expand All @@ -32,7 +33,7 @@ public function processArgs(
): array
{
$args = [];
foreach ($methodCallArgs as $arg) {
foreach ($methodCallArgs as $argIndex => $arg) {
if ($arg->unpack) {
throw new DynamicQueryBuilderArgumentException();
}
Expand Down Expand Up @@ -61,12 +62,14 @@ public function processArgs(
if ($value->isClassString()->yes() && count($value->getClassStringObjectType()->getObjectClassNames()) === 1) {
/** @var class-string $className */
$className = $value->getClassStringObjectType()->getObjectClassNames()[0];
if ($this->objectMetadataResolver->isTransient($className)) {
throw new DynamicQueryBuilderArgumentException();
$isEntityClassArgument = $argIndex === 0 && in_array($methodName, ['from', 'join', 'innerJoin', 'leftJoin'], true);
if ($isEntityClassArgument) {
if ($this->objectMetadataResolver->isTransient($className)) {
throw new DynamicQueryBuilderArgumentException();
}
$args[] = $className;
continue;
}

$args[] = $className;
continue;
}

if (count($value->getConstantScalarValues()) !== 1) {
Expand Down
10 changes: 10 additions & 0 deletions tests/Type/Doctrine/data/QueryResult/queryBuilderGetQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,4 +310,14 @@ public function testNonEntityClassString(EntityManagerInterface $em, string $cla
assertType('mixed', $result);
}

public function testEventAlias(EntityManagerInterface $em): void
{
$query = $em->createQueryBuilder()
->select('event')
->from(Many::class, 'event')
->getQuery();

assertType('Doctrine\ORM\Query<null, QueryResult\Entities\Many>', $query);
}

}
Loading