Skip to content

Commit 2e48d1a

Browse files
committedSep 21, 2022
Use a @template for countDistinct
1 parent bfefffe commit 2e48d1a

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed
 

‎stubs/ORM/Query/Expr.stub

+8
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,12 @@ class Expr
3131
{
3232
}
3333

34+
/**
35+
* @template T of string
36+
* @param T ...$x
37+
* @return (T is literal-string ? literal-string : string)
38+
*/
39+
public function countDistinct(...$x) {
40+
}
41+
3442
}

‎tests/Type/Doctrine/data/QueryResult/expressionBuilderGetQuery.php

+38
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,44 @@ public function betweenNonLiteralString3(EntityManagerInterface $em): void
6767
assertType('string', $result);
6868
}
6969

70+
public function countDistinctLiteralString(EntityManagerInterface $em): void
71+
{
72+
$result = $em->createQueryBuilder()->expr()->countDistinct('A', 'B', 'C');
73+
assertType("'COUNT(DISTINCT A, B, C)'", $result); // A ConstantStringType isLiteralString
74+
}
75+
76+
public function countDistinctNonLiteralString1(EntityManagerInterface $em): void
77+
{
78+
$value = $this->nonLiteralString('A');
79+
$result = $em->createQueryBuilder()->expr()->countDistinct($value);
80+
assertType('string', $result);
81+
}
82+
83+
public function countDistinctNonLiteralString2(EntityManagerInterface $em): void
84+
{
85+
$value = $this->nonLiteralString('A');
86+
$result = $em->createQueryBuilder()->expr()->countDistinct($value, 'B', 'C');
87+
assertType('string', $result);
88+
}
89+
90+
// Disabled until Doctrine ORM 3.0.0, as the countDistinct() function definition does not use `countDistinct(...$x)`
91+
// https://github.com/doctrine/orm/pull/9911
92+
// https://github.com/phpstan/phpstan-doctrine/pull/352
93+
//
94+
// public function countDistinctNonLiteralString3(EntityManagerInterface $em): void
95+
// {
96+
// $value = $this->nonLiteralString('B');
97+
// $result = $em->createQueryBuilder()->expr()->countDistinct('A', $value, 'C');
98+
// assertType('string', $result);
99+
// }
100+
//
101+
// public function countDistinctNonLiteralString4(EntityManagerInterface $em): void
102+
// {
103+
// $value = $this->nonLiteralString('C');
104+
// $result = $em->createQueryBuilder()->expr()->countDistinct('A', 'B', $value);
105+
// assertType('string', $result);
106+
// }
107+
70108
// Might be a problem, as these do not return a 'literal-string'.
71109
// As in, functions to support MOD() and ABS() return stringable value objects (Expr\Func).
72110
public function isNullNonLiteralStringExprFunc(EntityManagerInterface $em): void

‎tests/Type/Doctrine/data/QueryResult/expressionBuilderGetQueryNoObjectManager.php

+38
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,44 @@ public function betweenNonLiteralString3(EntityManagerInterface $em): void
6767
assertType('string', $result);
6868
}
6969

70+
public function countDistinctLiteralString(EntityManagerInterface $em): void
71+
{
72+
$result = $em->createQueryBuilder()->expr()->countDistinct('A', 'B', 'C');
73+
assertType('literal-string', $result);
74+
}
75+
76+
public function countDistinctNonLiteralString1(EntityManagerInterface $em): void
77+
{
78+
$value = $this->nonLiteralString('A');
79+
$result = $em->createQueryBuilder()->expr()->countDistinct($value);
80+
assertType('string', $result);
81+
}
82+
83+
public function countDistinctNonLiteralString2(EntityManagerInterface $em): void
84+
{
85+
$value = $this->nonLiteralString('A');
86+
$result = $em->createQueryBuilder()->expr()->countDistinct($value, 'B', 'C');
87+
assertType('string', $result);
88+
}
89+
90+
// Disabled until Doctrine ORM 3.0.0, as the countDistinct() function definition does not use `countDistinct(...$x)`
91+
// https://github.com/doctrine/orm/pull/9911
92+
// https://github.com/phpstan/phpstan-doctrine/pull/352
93+
//
94+
// public function countDistinctNonLiteralString3(EntityManagerInterface $em): void
95+
// {
96+
// $value = $this->nonLiteralString('B');
97+
// $result = $em->createQueryBuilder()->expr()->countDistinct('A', $value, 'C');
98+
// assertType('string', $result);
99+
// }
100+
//
101+
// public function countDistinctNonLiteralString4(EntityManagerInterface $em): void
102+
// {
103+
// $value = $this->nonLiteralString('C');
104+
// $result = $em->createQueryBuilder()->expr()->countDistinct('A', 'B', $value);
105+
// assertType('string', $result);
106+
// }
107+
70108
// Might be a problem, as these do not return a 'literal-string'.
71109
// As in, functions to support MOD() and ABS() return stringable value objects (Expr\Func).
72110
public function isNullNonLiteralStringExprFunc(EntityManagerInterface $em): void

0 commit comments

Comments
 (0)