@@ -854,8 +854,7 @@ private function resolveType(Expr $node): Type
854854 $ uncertainty = false ;
855855
856856 if ($ node ->class instanceof Node \Name) {
857- $ className = $ this ->resolveName ($ node ->class );
858- $ classType = new ObjectType ($ className );
857+ $ classType = $ this ->resolveTypeByName ($ node ->class );
859858 } else {
860859 $ classType = $ this ->getType ($ node ->class );
861860 $ classType = TypeTraverser::map ($ classType , static function (Type $ type , callable $ traverse ) use (&$ uncertainty ): Type {
@@ -1771,7 +1770,7 @@ private function resolveType(Expr $node): Type
17711770 if ($ resolvedName === 'parent ' && strtolower ($ constantName ) === 'class ' ) {
17721771 return new ClassStringType ();
17731772 }
1774- $ constantClassType = new ObjectType ( $ resolvedName );
1773+ $ constantClassType = $ this -> resolveTypeByName ( $ node -> class );
17751774 }
17761775
17771776 if (strtolower ($ constantName ) === 'class ' ) {
@@ -1932,7 +1931,7 @@ private function resolveType(Expr $node): Type
19321931 if ($ node instanceof Expr \StaticCall && $ node ->name instanceof Node \Identifier) {
19331932 $ typeCallback = function () use ($ node ): Type {
19341933 if ($ node ->class instanceof Name) {
1935- $ staticMethodCalledOnType = new ObjectType ( $ this ->resolveName ($ node ->class ) );
1934+ $ staticMethodCalledOnType = $ this ->resolveTypeByName ($ node ->class );
19361935 } else {
19371936 $ staticMethodCalledOnType = $ this ->getType ($ node ->class );
19381937 if ($ staticMethodCalledOnType instanceof GenericClassStringType) {
@@ -2045,7 +2044,7 @@ private function resolveType(Expr $node): Type
20452044 ) {
20462045 $ typeCallback = function () use ($ node ): Type {
20472046 if ($ node ->class instanceof Name) {
2048- $ staticPropertyFetchedOnType = new ObjectType ( $ this ->resolveName ($ node ->class ) );
2047+ $ staticPropertyFetchedOnType = $ this ->resolveTypeByName ($ node ->class );
20492048 } else {
20502049 $ staticPropertyFetchedOnType = $ this ->getType ($ node ->class );
20512050 if ($ staticPropertyFetchedOnType instanceof GenericClassStringType) {
@@ -2448,6 +2447,25 @@ public function resolveName(Name $name): string
24482447 return $ originalClass ;
24492448 }
24502449
2450+ public function resolveTypeByName (Name $ name ): TypeWithClassName
2451+ {
2452+ if ($ name ->toLowerString () === 'static ' && $ this ->isInClass ()) {
2453+ $ classReflection = $ this ->getClassReflection ();
2454+
2455+ return new StaticType ($ classReflection ->getName ());
2456+ }
2457+ $ originalClass = $ this ->resolveName ($ name );
2458+ if ($ this ->isInClass ()) {
2459+ $ thisType = new ThisType ($ this ->getClassReflection ());
2460+ $ ancestor = $ thisType ->getAncestorWithClassName ($ originalClass );
2461+ if ($ ancestor !== null ) {
2462+ return $ ancestor ;
2463+ }
2464+ }
2465+
2466+ return new ObjectType ($ originalClass );
2467+ }
2468+
24512469 /**
24522470 * @param mixed $value
24532471 */
0 commit comments