-
Notifications
You must be signed in to change notification settings - Fork 432
New issue
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
Add ArraySum dynamic return type extension #490
Conversation
@@ -178,4 +178,16 @@ | |||
$fooArray = ['foo']; | |||
$poppedFoo = array_pop($fooArray); | |||
|
|||
/** @var int[] $integers */ | |||
$sumInts = array_sum($integers); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the modern way of testing this, look at NodeScopeResolver::testFileAsserts
.
return ParametersAcceptorSelector::selectSingle($functionReflection->getVariants())->getReturnType(); | ||
} | ||
|
||
$arrayType = $scope->getType($functionCall->args[0]->value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty array always returns 0
, this extension should honor that. You should ask for $arrayType->isIterableAtLeastOnce()->no()
.
return $itemType; | ||
} | ||
|
||
return ParametersAcceptorSelector::selectSingle($functionReflection->getVariants())->getReturnType(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of the rest of the function, you can do just return TypeCombinator::intersect($itemType, new UnionType([new IntegerType(), new FloatType()]))
.
60ef5e9
to
a20d860
Compare
It should be ok now @ondrejmirtes :) |
Thank you! |
No description provided.