sort(), rsort() and usort() converts an array to list#2891
sort(), rsort() and usort() converts an array to list#2891ondrejmirtes merged 3 commits intophpstan:1.10.xfrom
sort(), rsort() and usort() converts an array to list#2891Conversation
|
Please have a look at phpstan/phpstan#3312 It seems also fixed by your PR. If so, please add a test |
|
Yes, this PR will fix it too. I added a test. |
src/Analyser/NodeScopeResolver.php
Outdated
| private function getArraySortFunctionType(Type $type): Type | ||
| { | ||
| if (!$type->isArray()->yes()) { | ||
| return new ErrorType(); |
There was a problem hiding this comment.
Just return the same $type instead
src/Analyser/NodeScopeResolver.php
Outdated
|
|
||
| $isIterableAtLeastOnce = $type->isIterableAtLeastOnce(); | ||
| if ($isIterableAtLeastOnce->no()) { | ||
| return new ConstantArrayType([], []); |
There was a problem hiding this comment.
Just return the same $type instead.
src/Analyser/NodeScopeResolver.php
Outdated
| $functionReflection !== null | ||
| && ( | ||
| (in_array($functionReflection->getName(), ['sort', 'rsort'], true) && count($expr->getArgs()) >= 1) | ||
| || ($functionReflection->getName() === 'usort' && count($expr->getArgs()) >= 2) |
There was a problem hiding this comment.
We don't need to complicate this by checking that the number of args is >= 2. Just check that the first arg is always there and join the condition into a single in_array.
|
@ondrejmirtes |
|
https://github.com/phpstan/phpstan-src/actions/runs/7682388532/job/20936712149 |
These errors were reported before, but they were in the baseline. So I think we can ignore the CI error. |
Yes we can :) |
|
Thank you! |
Closes phpstan/phpstan#6467
Closes phpstan/phpstan#10423
Closes phpstan/phpstan#3312