-
Notifications
You must be signed in to change notification settings - Fork 516
Impl StrIncrementDecrementFunctionReturnTypeExtension #2776
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
Impl StrIncrementDecrementFunctionReturnTypeExtension #2776
Conversation
} | ||
} | ||
|
||
return (string)++$s; |
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.
d228654
to
1bb4a34
Compare
resources/functionMap_php83delta.php
Outdated
return [ | ||
'new' => [ | ||
'str_decrement' => ['non-empty-string'], | ||
'str_increment' => ['non-falsy-string'], |
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.
This signature is wrong. The functions also have parameters.
src/Type/Php/StrIncrementDecrementFunctionReturnTypeExtension.php
Outdated
Show resolved
Hide resolved
{ | ||
if (function_exists('str_increment')) { | ||
try { | ||
return str_increment($s); |
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.
Or maybe we can always call our own implementation and not have a different one here.
1bb4a34
to
77dbe4f
Compare
$args = $functionCall->getArgs(); | ||
|
||
if (count($args) !== 1) { | ||
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.
You can just return null
in these cases
return ParametersAcceptorSelector::selectSingle($functionReflection->getVariants())->getReturnType(); | ||
} | ||
|
||
$value = $argType->getConstantScalarValues()[0]; |
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.
You should account for union of values, don't just read the first one
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.
I see, I misunderstood UnionType::getConstantScalarValues()
.
e5616f6
to
f903595
Compare
f903595
to
a8eb826
Compare
Thank you! |
Add types to
str_increment()
andstr_decrement()
added in PHP 8.3.However, unlike something like
strtolower()
, I can't think of many use cases for incrementing/decrementing constants, so it makes sense to reject this PR.