Better typing for mb_convert_encoding#3749
Closed
jack-worman wants to merge 3 commits intophpstan:2.1.xfrom
Closed
Better typing for mb_convert_encoding#3749jack-worman wants to merge 3 commits intophpstan:2.1.xfrom
jack-worman wants to merge 3 commits intophpstan:2.1.xfrom
Conversation
e514bc3 to
6f121ae
Compare
jack-worman
commented
Dec 21, 2024
| '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'], |
Contributor
Author
There was a problem hiding this comment.
Is there a way to represent a recursive type?
Or is only going 3 layers deep good enough?
Contributor
There was a problem hiding this comment.
I think the best would be to use string|array<mixed>|false
7004ae4 to
8a95b77
Compare
8a95b77 to
daee21d
Compare
zonuexe
reviewed
Jan 2, 2025
4f4c8f5 to
026cb29
Compare
Contributor
VincentLanglet
left a comment
There was a problem hiding this comment.
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 | |||
Contributor
There was a problem hiding this comment.
Existing bug are generally not removed but updated. (to see the diff)
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)]); |
Contributor
There was a problem hiding this comment.
TypeCombinator::union($argType, new ConstantBooleanType(false))
should be used. And it's not ok for constants array or constant strings.
Member
|
Succeeeded by #3914 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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