9
9
use PHPStan \Broker \AnonymousClassNameHelper ;
10
10
use PHPStan \File \FileHelper ;
11
11
use PHPStan \Parser \Parser ;
12
+ use PHPStan \PhpDoc \NameScopeAlreadyBeingCreatedException ;
12
13
use PHPStan \PhpDoc \PhpDocNodeResolver ;
13
14
use PHPStan \PhpDoc \PhpDocStringResolver ;
14
15
use PHPStan \PhpDoc \ResolvedPhpDocBlock ;
@@ -99,22 +100,42 @@ public function getResolvedPhpDoc(
99
100
return $ this ->createResolvedPhpDocBlock ($ phpDocKey , new NameScope (null , []), $ docComment , null );
100
101
}
101
102
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 );
102
123
$ nameScopeMap = [];
103
124
104
125
if (!isset ($ this ->inProcess [$ fileName ])) {
105
126
$ nameScopeMap = $ this ->getNameScopeMap ($ fileName );
106
127
}
107
128
108
129
if (isset ($ nameScopeMap [$ nameScopeKey ])) {
109
- return $ this -> createResolvedPhpDocBlock ( $ phpDocKey , $ nameScopeMap [$ nameScopeKey ], $ docComment , $ fileName ) ;
130
+ return $ nameScopeMap [$ nameScopeKey ];
110
131
}
111
132
112
133
if (!isset ($ this ->inProcess [$ fileName ][$ nameScopeKey ])) { // wrong $fileName due to traits
113
- return ResolvedPhpDocBlock:: createEmpty ();
134
+ throw new NameScopeAlreadyBeingCreatedException ();
114
135
}
115
136
116
137
if ($ this ->inProcess [$ fileName ][$ nameScopeKey ] === true ) { // PHPDoc has cyclic dependency
117
- return ResolvedPhpDocBlock:: createEmpty ();
138
+ throw new NameScopeAlreadyBeingCreatedException ();
118
139
}
119
140
120
141
if (is_callable ($ this ->inProcess [$ fileName ][$ nameScopeKey ])) {
@@ -123,7 +144,7 @@ public function getResolvedPhpDoc(
123
144
$ this ->inProcess [$ fileName ][$ nameScopeKey ] = $ resolveCallback ();
124
145
}
125
146
126
- return $ this ->createResolvedPhpDocBlock ( $ phpDocKey , $ this -> inProcess [$ fileName ][$ nameScopeKey ], $ docComment , $ fileName ) ;
147
+ return $ this ->inProcess [$ fileName ][$ nameScopeKey ];
127
148
}
128
149
129
150
private function createResolvedPhpDocBlock (string $ phpDocKey , NameScope $ nameScope , string $ phpDocString , ?string $ fileName ): ResolvedPhpDocBlock
0 commit comments