@@ -25,24 +25,7 @@ public function determineType(
2525bool  $ allowSameClass ,
2626): Type 
2727{
28- $ objectOrClassTypeClassNameType  = TypeTraverser::map (
29- $ objectOrClassType ,
30- static  function  (Type   $ type , callable  $ traverse ): Type   {
31- if  ($ type  instanceof  UnionType || $ type  instanceof  IntersectionType) {
32- return  $ traverse ($ type );
33- }
34- if  ($ type  instanceof  GenericClassStringType) {
35- return  $ traverse ($ type ->getGenericType ());
36- }
37- if  ($ type  instanceof  TypeWithClassName) {
38- return  $ type ;
39- }
40- return  new  ObjectType ('' );
41- },
42- );
43- $ objectOrClassTypeClassName  = $ objectOrClassTypeClassNameType  instanceof  TypeWithClassName
44- ? $ objectOrClassTypeClassNameType ->getClassName ()
45- : null ;
28+ $ objectOrClassTypeClassName  = $ this  ->determineClassNameFromObjectOrClassType ($ objectOrClassType );
4629
4730return  TypeTraverser::map (
4831$ classType ,
@@ -64,18 +47,14 @@ static function (Type $type, callable $traverse) use ($objectOrClassTypeClassNam
6447return  new  ObjectType ($ type ->getValue ());
6548}
6649if  ($ type  instanceof  GenericClassStringType) {
67- $ genericType  = $ type ->getGenericType ();
68- if  (!$ allowSameClass  && $ genericType  instanceof  TypeWithClassName && $ genericType ->getClassName () === $ objectOrClassTypeClassName ) {
69- return  new  NeverType ();
70- }
7150if  ($ allowString ) {
7251return  TypeCombinator::union (
73- $ genericType  ,
52+ $ type -> getGenericType () ,
7453$ type ,
7554);
7655}
7756
78- return  $ genericType  ;
57+ return  $ type -> getGenericType () ;
7958}
8059if  ($ allowString ) {
8160return  TypeCombinator::union (
@@ -89,4 +68,17 @@ static function (Type $type, callable $traverse) use ($objectOrClassTypeClassNam
8968);
9069}
9170
71+ private  function  determineClassNameFromObjectOrClassType (Type   $ type ): ?string 
72+ {
73+ if  ($ type  instanceof  TypeWithClassName) {
74+ return  $ type ->getClassName ();
75+ }
76+ 
77+ if  ($ type  instanceof  ConstantStringType) {
78+ return  $ type ->getValue ();
79+ }
80+ 
81+ return  null ;
82+ }
83+ 
9284}
0 commit comments