Skip to content

Commit

Permalink
Support class-string<T> in ->from
Browse files Browse the repository at this point in the history
  • Loading branch information
janedbal authored and ondrejmirtes committed Jan 14, 2024
1 parent 4547795 commit 7604bc1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Type/Doctrine/ArgumentsProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ public function processArgs(
$args[] = $array;
continue;
}

if ($value->isClassStringType()->yes() && count($value->getClassStringObjectType()->getObjectClassNames()) === 1) {
$args[] = $value->getClassStringObjectType()->getObjectClassNames()[0];
continue;
}

if (count($value->getConstantScalarValues()) !== 1) {
throw new DynamicQueryBuilderArgumentException();
}
Expand Down
29 changes: 29 additions & 0 deletions tests/Type/Doctrine/data/QueryResult/queryBuilderGetQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,33 @@ public function testDynamicMethodCall(
assertType('mixed', $result);
}


/**
* @param class-string<Many> $many
*/
public function testRegularClassString(EntityManagerInterface $em, string $many)
{
$result = $em->createQueryBuilder()
->select("m")
->from($many, 'm')
->getQuery()
->getResult();

assertType('list<QueryResult\Entities\Many>', $result);
}
/**
* @param class-string<T> $many
* @template T of Many
*/
public function testTemplatedClassString(EntityManagerInterface $em, string $many)
{
$result = $em->createQueryBuilder()
->select("m")
->from($many, 'm')
->getQuery()
->getResult();

assertType('list<QueryResult\Entities\Many>', $result);
}

}

0 comments on commit 7604bc1

Please sign in to comment.