3
3
namespace PHPStan \Reflection ;
4
4
5
5
use Attribute ;
6
+ use LogicException ;
6
7
use PhpParser \Node \Arg ;
7
8
use PhpParser \Node \Expr \StaticCall ;
8
9
use PhpParser \Node \Identifier ;
@@ -945,7 +946,11 @@ public function getEnumCases(): array
945
946
foreach ($ this ->reflection ->getCases () as $ case ) {
946
947
$ valueType = null ;
947
948
if ($ case instanceof ReflectionEnumBackedCase) {
948
- $ valueType = $ this ->initializerExprTypeResolver ->getType ($ case ->getValueExpression (), $ initializerExprContext );
949
+ try {
950
+ $ valueType = $ this ->initializerExprTypeResolver ->getType ($ case ->getValueExpression (), $ initializerExprContext );
951
+ } catch (LogicException ) {
952
+ // Enum case does not have a value
953
+ }
949
954
}
950
955
$ caseName = $ case ->getName ();
951
956
$ attributes = $ this ->attributeReflectionFactory ->fromNativeReflection ($ case ->getAttributes (), InitializerExprContext::fromClass ($ this ->getName (), $ this ->getFileName ()));
@@ -972,7 +977,11 @@ public function getEnumCase(string $name): EnumCaseReflection
972
977
$ case = $ this ->reflection ->getCase ($ name );
973
978
$ valueType = null ;
974
979
if ($ case instanceof ReflectionEnumBackedCase) {
975
- $ valueType = $ this ->initializerExprTypeResolver ->getType ($ case ->getValueExpression (), InitializerExprContext::fromClassReflection ($ this ));
980
+ try {
981
+ $ valueType = $ this ->initializerExprTypeResolver ->getType ($ case ->getValueExpression (), InitializerExprContext::fromClassReflection ($ this ));
982
+ } catch (LogicException ) {
983
+ // Enum case does not have a value
984
+ }
976
985
}
977
986
978
987
$ attributes = $ this ->attributeReflectionFactory ->fromNativeReflection ($ case ->getAttributes (), InitializerExprContext::fromClass ($ this ->getName (), $ this ->getFileName ()));
0 commit comments