phpstan-doctrine
phpstan-doctrine copied to clipboard
stubs/ORM/Query/Expr.stub wrongs params
Hi, i got this error :
Parameter #2 $x of method Doctrine\ORM\Query\Expr::between() expects string, int|string given
But if i look in lib/Doctrine/ORM/Query/Expr.php, i got theses params :
* @param mixed $val Valued to be inspected by range values.
* @param int|string $x Starting range value to be used in BETWEEN() function.
* @param int|string $y End point value to be used in BETWEEN() function.
I solved it on my side by casting my int into string, but i guess the stubs/ORM/Query/Expr.stub is wrong, or maybe i misunderstood something.
* @param string $val
* @param string $x
* @param string $y
Im using phpstan-doctrine 1.3.13, phpstan/phpstan 1.8.5, phpstan/phpstan-symfony 1.2.13 and doctrine/orm 2.13.1
- Research when the int type was added/removed in the Git history of the library
- If the int type doesn't look deprecated and is going to be supported into the future, send a PR here with a stub update.
The stub was introduced by @craigfrancis in https://github.com/phpstan/phpstan-doctrine/pull/324
And this doesn't seems to be deprecated https://github.com/doctrine/orm/blob/0aa45dd607100182294d31dee42b89338773f87e/lib/Doctrine/ORM/Query/Expr.php#L638-L650
But there is a conditional return type:
@return ($val is literal-string ? ($x is literal-string ? ($y is literal-string ? literal-string&non-empty-string : string) : string) : string)
which will maybe need to be updated since $x and $y can be int.
If I look at https://phpstan.org/r/9324b003-b39b-49c9-b911-13a6d4521638
(string) $intis not considered as literal- literal-int doesn't exists.
So, I'm not sure there is a solution to infer
->between('literal', 1, 9)
as a literal-string since
->between('literal', '1', '9')
does.
Thanks for finding Vincent,
I've created PR #407, which simply allows int values for these arguments.
There is no need to change the conditional return type, as it shouldn't return a literal-string when an integer is used.
The failing "mod function error" test should be unrelated to my changes.
As an aside, I'm drafting the LiteralString PHP RFC, and I've got an Integer Values section which hopefully summarises why PHP won't be able to support literal-int (which I'm still disappointed about, and that's why I don't think static analysis tools should support it either).
The failing "mod function error" test should be unrelated to my changes.
Yes, it's fixed in https://github.com/phpstan/phpstan-doctrine/pull/405
There is no need to change the conditional return type, as it shouldn't return a
literal-stringwhen an integer is used.As an aside, I'm drafting the LiteralString PHP RFC, and I've got an Integer Values section which hopefully summarises why PHP won't be able to support
literal-int(which I'm still disappointed about, and that's why I don't think static analysis tools should support it either).
The method were doing
$a . ' BETWEEN ' . $b
So I would expect that both
'1'. ' BETWEEN ' . '2'
1. ' BETWEEN ' . 2
were considered as literal.
But looking at the RFC seems like it won't be possible :/
Thanks for checking Vincent.
And yeah, it's annoying, but integers in PHP don't have the ability to add a literal flag onto them (not without major changes to the zval structure).
Fixed by https://github.com/phpstan/phpstan-doctrine/pull/407
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.