We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AbstractQuery::getSingleScalarResult
It appears that getSingleScalarResult() currently always returns bool|float|int|string|null.
getSingleScalarResult()
bool|float|int|string|null
If I have the following query:
$result = $this->createQueryBuilder('u') ->select('COUNT(u.id)') ->where('u.is_deleted = false') ->getQuery() ->getSingleScalarResult(); \PHPStan\assertType($result, 'bool|float|int|string|null');
But when I do getResult() it works properly:
getResult()
$result = $this->createQueryBuilder('u') ->select('COUNT(u.id)') ->where('u.is_deleted = false') ->getQuery() ->getSingleScalarResult(); \PHPStan\assertType($result, 'list<array{1: int<0, max>}>');
I wonder why we cannot support getSingleScalarResult? I created the following helper:
getSingleScalarResult
/** * @template TValue of scalar * @param list<array{1: TValue}> $results * * @return TValue */ protected function getSingleScalarResult(array $results) : bool | float | int | string { return $results[0][array_key_first($results[0])]; }
And now this works great:
$result = $this->getSingleScalarResult($this->createQueryBuilder('u') ->select('COUNT(u.id)') ->where('u.is_deleted = false') ->getQuery() ->getResult()); \PHPStan\assertType($result, 'int<0, max>');
Am I being naive here and is there a flaw with my solution or would it be possible to support it 😁?
/cc @arnaud-lb @janedbal
References:
The text was updated successfully, but these errors were encountered:
Not as easy as it looks.
See
Sorry, something went wrong.
I'd recommend using https://github.com/staabm/phpstan-dba additionally which resolves types much narrower for most queries.
No branches or pull requests
It appears that
getSingleScalarResult()
currently always returnsbool|float|int|string|null
.If I have the following query:
But when I do
getResult()
it works properly:I wonder why we cannot support
getSingleScalarResult
? I created the following helper:And now this works great:
Am I being naive here and is there a flaw with my solution or would it be possible to support it 😁?
/cc @arnaud-lb @janedbal
References:
The text was updated successfully, but these errors were encountered: