-
Notifications
You must be signed in to change notification settings - Fork 548
Better typing for mb_convert_encoding #3749
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
Better typing for mb_convert_encoding #3749
Conversation
e514bc3 to
6f121ae
Compare
| 'mb_chr' => ['string|false', 'cp'=>'int', 'encoding='=>'string'], | ||
| 'mb_convert_case' => ['string', 'sourcestring'=>'string', 'mode'=>'int', 'encoding='=>'string'], | ||
| 'mb_convert_encoding' => ['string|array<int, string>|false', 'val'=>'string|array<int, string>', 'to_encoding'=>'string', 'from_encoding='=>'mixed'], | ||
| 'mb_convert_encoding' => ['string|array<scalar|null|array<scalar|null>>|false', 'val'=>'string|array<scalar|null|array<scalar|null>>', 'to_encoding'=>'string', 'from_encoding='=>'mixed'], |
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.
Is there a way to represent a recursive type?
Or is only going 3 layers deep good enough?
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 think the best would be to use string|array<mixed>|false
7004ae4 to
8a95b77
Compare
8a95b77 to
daee21d
Compare
4f4c8f5 to
026cb29
Compare
VincentLanglet
left a comment
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.
It's possible to produce a false return value, for instance with
mb_convert_encoding("\x80\x81\x82", "UTF-8", 'auto')
So I'm unsure about changing the Union to a BenevolentUnion.
People should be advised to add a false check on the result.
| @@ -1,10 +0,0 @@ | |||
| <?php // lint < 8.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.
Existing bug are generally not removed but updated. (to see the diff)
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.
reverted delete
ef98d62 to
1f7fe1c
Compare
50cf201 to
1c5bdc0
Compare
1c5bdc0 to
e258559
Compare
| return new ArrayType(new IntegerType(), new StringType()); | ||
| $argType = $scope->getType($args[0]->value); | ||
| if ($argType->isString()->yes() || $argType->isArray()->yes()) { | ||
| return new UnionType([$argType, new ConstantBooleanType(false)]); |
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.
TypeCombinator::union($argType, new ConstantBooleanType(false))
should be used. And it's not ok for constants array or constant strings.
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 think #3914 does the job
|
Succeeeded by #3914 |
Closes phpstan/phpstan#12309
Also, fixed types related to the array input and output; the output array has the exact same shape as the input array: https://3v4l.org/OrdDb