99use PHPStan \Broker \AnonymousClassNameHelper ;
1010use PHPStan \File \FileHelper ;
1111use PHPStan \Parser \Parser ;
12+ use PHPStan \PhpDoc \NameScopeAlreadyBeingCreatedException ;
1213use PHPStan \PhpDoc \PhpDocNodeResolver ;
1314use PHPStan \PhpDoc \PhpDocStringResolver ;
1415use PHPStan \PhpDoc \ResolvedPhpDocBlock ;
@@ -99,22 +100,42 @@ public function getResolvedPhpDoc(
99100 return $ this ->createResolvedPhpDocBlock ($ phpDocKey , new NameScope (null , []), $ docComment , null );
100101 }
101102
103+ try {
104+ $ nameScope = $ this ->getNameScope ($ fileName , $ className , $ traitName , $ functionName );
105+ } catch (NameScopeAlreadyBeingCreatedException ) {
106+ return ResolvedPhpDocBlock::createEmpty ();
107+ }
108+
109+ return $ this ->createResolvedPhpDocBlock ($ phpDocKey , $ nameScope , $ docComment , $ fileName );
110+ }
111+
112+ /**
113+ * @throws NameScopeAlreadyBeingCreatedException
114+ */
115+ public function getNameScope (
116+ string $ fileName ,
117+ ?string $ className ,
118+ ?string $ traitName ,
119+ ?string $ functionName ,
120+ ): NameScope
121+ {
122+ $ nameScopeKey = $ this ->getNameScopeKey ($ fileName , $ className , $ traitName , $ functionName );
102123 $ nameScopeMap = [];
103124
104125 if (!isset ($ this ->inProcess [$ fileName ])) {
105126 $ nameScopeMap = $ this ->getNameScopeMap ($ fileName );
106127 }
107128
108129 if (isset ($ nameScopeMap [$ nameScopeKey ])) {
109- return $ this -> createResolvedPhpDocBlock ( $ phpDocKey , $ nameScopeMap [$ nameScopeKey ], $ docComment , $ fileName ) ;
130+ return $ nameScopeMap [$ nameScopeKey ];
110131 }
111132
112133 if (!isset ($ this ->inProcess [$ fileName ][$ nameScopeKey ])) { // wrong $fileName due to traits
113- return ResolvedPhpDocBlock:: createEmpty ();
134+ throw new NameScopeAlreadyBeingCreatedException ();
114135 }
115136
116137 if ($ this ->inProcess [$ fileName ][$ nameScopeKey ] === true ) { // PHPDoc has cyclic dependency
117- return ResolvedPhpDocBlock:: createEmpty ();
138+ throw new NameScopeAlreadyBeingCreatedException ();
118139 }
119140
120141 if (is_callable ($ this ->inProcess [$ fileName ][$ nameScopeKey ])) {
@@ -123,7 +144,7 @@ public function getResolvedPhpDoc(
123144 $ this ->inProcess [$ fileName ][$ nameScopeKey ] = $ resolveCallback ();
124145 }
125146
126- return $ this ->createResolvedPhpDocBlock ( $ phpDocKey , $ this -> inProcess [$ fileName ][$ nameScopeKey ], $ docComment , $ fileName ) ;
147+ return $ this ->inProcess [$ fileName ][$ nameScopeKey ];
127148 }
128149
129150 private function createResolvedPhpDocBlock (string $ phpDocKey , NameScope $ nameScope , string $ phpDocString , ?string $ fileName ): ResolvedPhpDocBlock
0 commit comments