-
Notifications
You must be signed in to change notification settings - Fork 488
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
Improved support for enum-string types #3807
Conversation
src/PhpDoc/TypeNodeResolver.php
Outdated
@@ -696,7 +698,7 @@ static function (string $variance): TemplateTypeVariance { | |||
if (count($genericTypes) === 2) { // iterable<KeyType, ValueType> | |||
return new IterableType($genericTypes[0], $genericTypes[1]); | |||
} | |||
} elseif (in_array($mainTypeName, ['class-string', 'interface-string'], true)) { | |||
} elseif (in_array($mainTypeName, ['class-string', 'interface-string', 'enum-string'], true)) { |
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 adding this elseif
clause, another idea is to add another clause.
- } elseif (in_array($mainTypeName, ['class-string', 'interface-string'], true)) {
+ } elseif ($mainTypeName === 'enum-string') {
if (count($genericTypes) === 1) {
$genericType = $genericTypes[0];
- if ($genericType->isObject()->yes() || $genericType instanceof MixedType) {
+ if ($genericType->isEnum()->yes() || $genericType instanceof MixedType) {
return new GenericClassStringType($genericType);
}
}
However, Psalm simply equates the three.
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.
We need to do TypeCombinator::intersect($genericType, new ObjectType(UnitEnum::class))
. You can then test it with enum-string<object>
and also enum-string<SomeInterface>
.
dcb943e
to
4901208
Compare
src/PhpDoc/TypeNodeResolver.php
Outdated
@@ -696,7 +698,7 @@ static function (string $variance): TemplateTypeVariance { | |||
if (count($genericTypes) === 2) { // iterable<KeyType, ValueType> | |||
return new IterableType($genericTypes[0], $genericTypes[1]); | |||
} | |||
} elseif (in_array($mainTypeName, ['class-string', 'interface-string'], true)) { | |||
} elseif (in_array($mainTypeName, ['class-string', 'interface-string', 'enum-string'], true)) { |
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.
We need to do TypeCombinator::intersect($genericType, new ObjectType(UnitEnum::class))
. You can then test it with enum-string<object>
and also enum-string<SomeInterface>
.
5eb8099
to
5eaf06a
Compare
This pull request has been marked as ready for review. |
Thank you! |
resolve phpstan/phpstan#12529
refs #2764