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
More precise signatures for mb_* functions #717
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
use PHPStan\Type\Constant\ConstantBooleanType; | ||
use PHPStan\Type\Constant\ConstantStringType; | ||
use PHPStan\Type\DynamicFunctionReturnTypeExtension; | ||
use PHPStan\Type\IntegerRangeType; | ||
use PHPStan\Type\StringType; | ||
use PHPStan\Type\Type; | ||
use PHPStan\Type\TypeCombinator; | ||
|
@@ -74,6 +75,11 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection, | |
$returnType = ParametersAcceptorSelector::selectSingle($functionReflection->getVariants())->getReturnType(); | ||
$positionEncodingParam = $this->encodingPositionMap[$functionReflection->getName()]; | ||
|
||
// php8-stubs define a regular int return-type for mb_strlen. use a more precise type instead. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it seems therefore we need this additional if-case There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you try putting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ahh that worked - thanks! |
||
if ($functionReflection->getName() === 'mb_strlen') { | ||
$returnType = IntegerRangeType::fromInterval(0, null); | ||
} | ||
|
||
if (count($functionCall->getArgs()) < $positionEncodingParam) { | ||
return TypeCombinator::remove($returnType, new BooleanType()); | ||
} | ||
|
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.
see https://3v4l.org/BSmeQ