File tree Expand file tree Collapse file tree 4 files changed +35
-2
lines changed
Expand file tree Collapse file tree 4 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -729,7 +729,7 @@ public function resolveExpressionNodeToType($expr)
729729 foreach ($ classDef ->getAncestorDefinitions ($ this ->index , true ) as $ fqn => $ def ) {
730730 $ def = $ this ->index ->getDefinition ($ fqn . $ add );
731731 if ($ def !== null ) {
732- if ($ def ->type instanceof Types \This) {
732+ if ($ def ->type instanceof Types \This || $ def -> type instanceof Types \Self_ ) {
733733 return new Types \Object_ (new Fqsen ('\\' . $ classFqn ));
734734 }
735735 return $ def ->type ;
@@ -1090,6 +1090,12 @@ public function getTypeFromNode($node)
10901090 if ($ node ->returnType instanceof PhpParser \Token) {
10911091 // Resolve a string like "bool" to a type object
10921092 return $ this ->typeResolver ->resolve ($ node ->returnType ->getText ($ node ->getFileContents ()));
1093+ } elseif ($ node ->returnType ->getResolvedName () === 'self ' ) {
1094+ $ classNode = $ node ->getFirstAncestor (Node \Statement \ClassDeclaration::class);
1095+ if ($ classNode ) {
1096+ $ classFqn = (string )$ classNode ->getNamespacedName ();
1097+ return new Types \Object_ (new Fqsen ('\\' . $ classFqn ));
1098+ }
10931099 }
10941100 return new Types \Object_ (new Fqsen ('\\' . (string )$ node ->returnType ->getResolvedName ()));
10951101 }
Original file line number Diff line number Diff line change 7171 },
7272 "containerName" : " Fixtures\\ Prophecy\\ WithReturnTypehints"
7373 },
74- "type__tostring" : " \\ self " ,
74+ "type__tostring" : " \\ Fixtures \\ Prophecy \\ WithReturnTypehints " ,
7575 "type" : {},
7676 "declarationLine" : " public function getSelf(): self {" ,
7777 "documentation" : null ,
Original file line number Diff line number Diff line change @@ -5,5 +5,7 @@ public static function staticFoo(): FooClass {
55 return new FooClass ();
66 }
77
8+ public static function staticSelf (): self { }
9+
810 public function bar () { }
911}
Original file line number Diff line number Diff line change 5050 "parameters" : []
5151 }
5252 },
53+ "FooClass::staticSelf()" : {
54+ "fqn" : " FooClass::staticSelf()" ,
55+ "extends" : [],
56+ "isMember" : true ,
57+ "roamed" : false ,
58+ "isStatic" : true ,
59+ "canBeInstantiated" : false ,
60+ "symbolInformation" : {
61+ "name" : " staticSelf" ,
62+ "kind" : 6 ,
63+ "location" : {
64+ "uri" : " ./staticMethodReturnType.php"
65+ },
66+ "containerName" : " FooClass"
67+ },
68+ "type__tostring" : " \\ FooClass" ,
69+ "type" : {},
70+ "declarationLine" : " public static function staticSelf(): self { }" ,
71+ "documentation" : null ,
72+ "signatureInformation" : {
73+ "label" : " ()" ,
74+ "documentation" : null ,
75+ "parameters" : []
76+ }
77+ },
5378 "FooClass->bar()" : {
5479 "fqn" : " FooClass->bar()" ,
5580 "extends" : [],
You can’t perform that action at this time.
0 commit comments