@@ -854,8 +854,7 @@ private function resolveType(Expr $node): Type
854
854
$ uncertainty = false ;
855
855
856
856
if ($ node ->class instanceof Node \Name) {
857
- $ className = $ this ->resolveName ($ node ->class );
858
- $ classType = new ObjectType ($ className );
857
+ $ classType = $ this ->resolveTypeByName ($ node ->class );
859
858
} else {
860
859
$ classType = $ this ->getType ($ node ->class );
861
860
$ classType = TypeTraverser::map ($ classType , static function (Type $ type , callable $ traverse ) use (&$ uncertainty ): Type {
@@ -1771,7 +1770,7 @@ private function resolveType(Expr $node): Type
1771
1770
if ($ resolvedName === 'parent ' && strtolower ($ constantName ) === 'class ' ) {
1772
1771
return new ClassStringType ();
1773
1772
}
1774
- $ constantClassType = new ObjectType ( $ resolvedName );
1773
+ $ constantClassType = $ this -> resolveTypeByName ( $ node -> class );
1775
1774
}
1776
1775
1777
1776
if (strtolower ($ constantName ) === 'class ' ) {
@@ -1932,7 +1931,7 @@ private function resolveType(Expr $node): Type
1932
1931
if ($ node instanceof Expr \StaticCall && $ node ->name instanceof Node \Identifier) {
1933
1932
$ typeCallback = function () use ($ node ): Type {
1934
1933
if ($ node ->class instanceof Name) {
1935
- $ staticMethodCalledOnType = new ObjectType ( $ this ->resolveName ($ node ->class ) );
1934
+ $ staticMethodCalledOnType = $ this ->resolveTypeByName ($ node ->class );
1936
1935
} else {
1937
1936
$ staticMethodCalledOnType = $ this ->getType ($ node ->class );
1938
1937
if ($ staticMethodCalledOnType instanceof GenericClassStringType) {
@@ -2045,7 +2044,7 @@ private function resolveType(Expr $node): Type
2045
2044
) {
2046
2045
$ typeCallback = function () use ($ node ): Type {
2047
2046
if ($ node ->class instanceof Name) {
2048
- $ staticPropertyFetchedOnType = new ObjectType ( $ this ->resolveName ($ node ->class ) );
2047
+ $ staticPropertyFetchedOnType = $ this ->resolveTypeByName ($ node ->class );
2049
2048
} else {
2050
2049
$ staticPropertyFetchedOnType = $ this ->getType ($ node ->class );
2051
2050
if ($ staticPropertyFetchedOnType instanceof GenericClassStringType) {
@@ -2448,6 +2447,25 @@ public function resolveName(Name $name): string
2448
2447
return $ originalClass ;
2449
2448
}
2450
2449
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
+
2451
2469
/**
2452
2470
* @param mixed $value
2453
2471
*/
0 commit comments