72964[BUGFIX] Streamline typehints of variadic arguments in QueryBuilder
Commit message
Review
-
Code review CR +2 Done
- Christian Kuhn +2
- Oliver Klee +1
- Stefan Bürk +1
- Oliver Hader +1
-
Verified V +2 Done
- Christian Kuhn +2
- Stefan Bürk +1
- core-ci +1 CI
Issues 2
Files 1
Review log 2832
Show 57 earlier messages
-
Elias Häußler uploaded patch set 1 01/11/22, 11:54
-
Elias Häußler updated the commit message in patch set 2 01/11/22, 11:55
-
Oliver Hader commented on patch set 2 CR -1 01/11/22, 11:58
-
Elias Häußler commented on patch set 2 01/11/22, 12:07
QueryBuilder.php:787ReplyMaybe I don't get it completely, but isn't `CompositeExpression` redundant here since it's already covered by `mixed`? Do we need this explicit type? In doctrine's QueryBuilder there is `mixed` as well. -
core-ci voted on patch set 1 V +1 01/11/22, 12:08 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/21902
-
core-ci voted on patch set 2 V +1 01/11/22, 12:13 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/21903
-
Ingo Fabbri commented on patch set 2 01/11/22, 12:36
QueryBuilder.php:787ReplyFirst, I am Sorry for the inconvenience caused. I don't even understand, why @param array<int,mixed> $predicates was even a valid typehint before. This function has variadic arguments. In most cases these methods would be called like: ``` ->andWhere( $queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter(42, \PDO::PARAM_INT)) ) ``` "eq" returns string. So it is rather just @param string ...$predicates So now I would say, to resolve this issue it would be completely safe to say: @param mixed ...$predicates is fine and meets the expectation of underlying doctrine querybuilder methods.
-
Oliver Hader voted on patch set 2 CR 0 01/11/22, 12:40
-
Ingo Fabbri voted on patch set 2 CR +1 01/11/22, 12:45
-
Stefan Bürk commented on patch set 2 01/11/22, 12:49
QueryBuilder.php:787Reply``` array<int,string>|CompositeExpression|string ``` would work also, for where(), andWhere() and orWhere() - and I would prefer this instead of a vague "mixed". At least this would make typo3/styleguide phpstan check / scheduled nightly green again. (Excpet that one ignore rule should be removed which was added because of the missint CompositeExpression and now not matching anymore. And was a @todo to be fixed in the core. See: https://github.com/TYPO3/styleguide/blob/2a51dc3db6c2916c07595dd96e8b817a73216002/Build/phpstan.neon#L16 -
Oliver Hader commented on patch set 2 01/11/22, 12:51
QueryBuilder.php:787ReplyMissed that the varadic part changes in the `@param` block * `@param mixed ...$predicates` is basically the same as `@param array<int, mixed> $predicates` * in order to include the hint to `CompositeExpression` it would be `@param mixed|CompositeExpression ...$predicates`, wouldn't it? -
Stefan Bürk commented on patch set 2 01/11/22, 12:52
QueryBuilder.php:787ReplyCompositeExpression is technicly only for the first argument, not as multiagrument. -
Oliver Hader commented on patch set 2 01/11/22, 12:54
QueryBuilder.php:787ReplyOr in other words: Reverting https://review.typo3.org/c/Packages/TYPO3.CMS/+/72858/5/typo3/sysext/core/Classes/Database/Query/QueryBuilder.php would have the same effect compared to the current patch... -
Stefan Bürk commented on patch set 2 01/11/22, 13:00
QueryBuilder.php:787ReplyYes and no. The goal of the original patch was to eliminate the need to declare phpstand ignores, like the linked one in typo3/styleguide. Reverting that patch will still need these ignores. Not sure why "where()" hat array<int,mixed> and orWhere()/andWhere array<int,string>, which is more correct, I would suggest to use following for all three methods: ``` array<int,string>|CompositeExpression|string ``` This will solve it for all consteallations, alow the CompositeExpression as first element or multi elements, and make the ignore for php stan im CompositExpression is passed as first element obsolete/superflous. Anyway .. better revert the other patch to restore long-standing behaviour if solving all issues would take longer time to discuss. -
Ingo Fabbri commented on patch set 2 01/11/22, 13:12
QueryBuilder.php:787ReplyThe original issue was: @param array<int,string> $where As this only allowed string arguments. Not CompositeExpression. Some methods already had @param array<int,mixed> $predicates which was fine. But technically: NOT only the first argument can be CompositeExpression. Please have an eye on that and verify. So if someone likes the old syntax: @param array<int,mixed> $predicates instead of @param array<int,string> $predicates would be super fine. But I like to takes advices from PHPSTAN doc, where it says: @param mixed ...$predicates -
Ingo Fabbri commented on patch set 2 01/11/22, 13:22
QueryBuilder.php:787Reply> array<int,string>|CompositeExpression|string Is not a valid annotation and results in 2 errors. https://phpstan.org/r/1ff5d9fa-d147-43d8-a204-2ebbbcb9f90b -
Stefan Bürk commented on patch set 2 01/11/22, 13:29
QueryBuilder.php:787ReplyThanks Ingo, you are right. not only the first one - was an overlook because of the param one check in doctrine/dbal. Anyway .. the "mixed" was to support the CompositeExpression for "where()", which was missed for andWhere() and orWhere(), thus having the phpstan ignore for typo3/styleguide. The first patch was a small failure - so to combine all, following should be the correct typehint for 'where()', 'orWhere()' and 'andWhere()': ``` @param string|CompositeExpression> ...$predicates The query restrictions. or (not sure which of both are better, fine with both and both green in styleguide) @param array<int,string|CompositeExpression> $predicates The query restrictions. ``` Or, if unsure, at use for "where()": ``` @param mixed|CompositeExpression> ...$predicates The query restrictions. or @param array<int,mixed|CompositeExpression> $predicates The query restrictions. ``` -
Stefan Bürk commented on patch set 2 01/11/22, 13:44
QueryBuilder.php:787Reply Unresolved -
Stefan Bürk uploaded patch set 3 01/11/22, 13:53
-
Stefan Bürk uploaded patch set 4 01/11/22, 13:54
-
Stefan Bürk voted on patch set 4 V +1 CR +1 01/11/22, 13:55
-
core-ci voted on patch set 3 V -1 01/11/22, 14:07 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/21908
-
core-ci voted on patch set 4 V +1 01/11/22, 14:08 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/21909
-
Oliver Klee voted on patch set 4 CR +1 01/11/22, 21:10
-
Oliver Hader commented on patch set 4 01/12/22, 10:01
I am wondering why this problem with PhpStan has not been discovered by TYPO3 CI-runs... We should ensure that these kind of misconfigurations are not happening again. However, I don't know why the problem did not occur in plain core. -
Stefan Bürk commented on patch set 4 01/12/22, 10:10
Reply
Maybe related to phpstan version ? Could not find ignores in the core files for phpstan. typo3/styleguide uses phpstan^1.2 ... and triggered that through the nightlies (scheduled). But right, core ci itself should find this. But not sure how and why. Anyway raising phpstan to ^1 has some dependencies to ... so not an easy one step. And I'm not a phpstan pro - so maybe someone else has a glue for the question ? -
Oliver Hader commented on patch set 4 01/12/22, 10:33
Reply
Disabling `checkThisOnly` in root `phpstan.neon` file seems to trigger those warnings. I absolutely don't know why this setting is there - I'm basically a PsalmPHP dude, but don't know much about PhpStan internals... -
Stefan Bürk commented on patch set 4 01/12/22, 10:41
Reply
You are right. And with the option it shows that this patch solves this. But it comes with a lot of other things, so could be activtaed simply. So how should we proceed here ? Fixing all that phpstan errors with removed "checkThisOnly" in dedicated patches as a small "epic" / task chain, which this one would be one of it, and activate afterwards ? Not sure how hard/possible this will get in respect of "backports". Quick view shows that there are quite some stuff which has been "missed" to, because of this hiding. -
Oliver Hader voted on patch set 4 CR +1 01/12/22, 12:52
-
Oliver Hader commented on patch set 4 01/12/22, 12:54
Reply
I've created an epic for that: https://forge.typo3.org/issues/96521, which is independent from this very patch-set -
Christian Kuhn voted on patch set 4 V +2 CR +2 01/13/22, 18:55
-
Christian Kuhn merged patch set 5 01/13/22, 18:55
QueryBuilder.php:787