88use PhpParser \Node \Stmt \Class_ ;
99use PhpParser \Node \Stmt \ClassMethod ;
1010use PhpParser \Node \Stmt \Function_ ;
11+ use PHPStan \Analyser \NamespaceUses ;
1112use PHPStan \Dependency \ExportedNode \ExportedAttributeNode ;
1213use PHPStan \Dependency \ExportedNode \ExportedClassConstantNode ;
1314use PHPStan \Dependency \ExportedNode \ExportedClassConstantsNode ;
@@ -44,7 +45,7 @@ public function __construct(
4445 {
4546 }
4647
47- public function resolve (Node $ node , ExportedNameScope $ nameScope ): ?RootExportedNode
48+ public function resolve (Node $ node , NamespaceUses $ namespaceUses ): ?RootExportedNode
4849 {
4950 if ($ node instanceof Class_ && isset ($ node ->namespacedName )) {
5051 $ docComment = $ node ->getDocComment ();
@@ -73,7 +74,7 @@ public function resolve(Node $node, ExportedNameScope $nameScope): ?RootExported
7374
7475 return new ExportedClassNode (
7576 $ className ,
76- $ this ->exportPhpDocNode ($ docComment !== null ? $ docComment ->getText () : null , $ nameScope ),
77+ $ this ->exportPhpDocNode ($ docComment !== null ? $ docComment ->getText () : null , $ namespaceUses ),
7778 $ node ->isAbstract (),
7879 $ node ->isFinal (),
7980 $ extendsName ,
@@ -99,7 +100,7 @@ public function resolve(Node $node, ExportedNameScope $nameScope): ?RootExported
99100
100101 throw new ShouldNotHappenException ();
101102 }, $ adaptations ),
102- $ this ->exportClassStatements ($ node ->stmts , $ className , $ nameScope ),
103+ $ this ->exportClassStatements ($ node ->stmts , $ className , $ namespaceUses ),
103104 $ this ->exportAttributeNodes ($ node ->attrGroups ),
104105 );
105106 }
@@ -112,9 +113,9 @@ public function resolve(Node $node, ExportedNameScope $nameScope): ?RootExported
112113
113114 return new ExportedInterfaceNode (
114115 $ interfaceName ,
115- $ this ->exportPhpDocNode ($ docComment !== null ? $ docComment ->getText () : null , $ nameScope ),
116+ $ this ->exportPhpDocNode ($ docComment !== null ? $ docComment ->getText () : null , $ namespaceUses ),
116117 $ extendsNames ,
117- $ this ->exportClassStatements ($ node ->stmts , $ interfaceName , $ nameScope ),
118+ $ this ->exportClassStatements ($ node ->stmts , $ interfaceName , $ namespaceUses ),
118119 );
119120 }
120121
@@ -131,9 +132,9 @@ public function resolve(Node $node, ExportedNameScope $nameScope): ?RootExported
131132 return new ExportedEnumNode (
132133 $ enumName ,
133134 $ scalarType ,
134- $ this ->exportPhpDocNode ($ docComment !== null ? $ docComment ->getText () : null , $ nameScope ),
135+ $ this ->exportPhpDocNode ($ docComment !== null ? $ docComment ->getText () : null , $ namespaceUses ),
135136 $ implementsNames ,
136- $ this ->exportClassStatements ($ node ->stmts , $ enumName , $ nameScope ),
137+ $ this ->exportClassStatements ($ node ->stmts , $ enumName , $ namespaceUses ),
137138 $ this ->exportAttributeNodes ($ node ->attrGroups ),
138139 );
139140 }
@@ -155,7 +156,7 @@ public function resolve(Node $node, ExportedNameScope $nameScope): ?RootExported
155156
156157 return new ExportedTraitNode (
157158 $ className ,
158- $ this ->exportPhpDocNode ($ docComment !== null ? $ docComment ->getText () : null , $ nameScope ),
159+ $ this ->exportPhpDocNode ($ docComment !== null ? $ docComment ->getText () : null , $ namespaceUses ),
159160 $ usedTraits ,
160161 array_map (static function (Node \Stmt \TraitUseAdaptation $ adaptation ): ExportedTraitUseAdaptation {
161162 if ($ adaptation instanceof Node \Stmt \TraitUseAdaptation \Alias) {
@@ -177,7 +178,7 @@ public function resolve(Node $node, ExportedNameScope $nameScope): ?RootExported
177178
178179 throw new ShouldNotHappenException ();
179180 }, $ adaptations ),
180- $ this ->exportClassStatements ($ node ->stmts , $ className , $ nameScope ),
181+ $ this ->exportClassStatements ($ node ->stmts , $ className , $ namespaceUses ),
181182 $ this ->exportAttributeNodes ($ node ->attrGroups ),
182183 );
183184 }
@@ -192,10 +193,10 @@ public function resolve(Node $node, ExportedNameScope $nameScope): ?RootExported
192193
193194 return new ExportedFunctionNode (
194195 $ functionName ,
195- $ this ->exportPhpDocNode ($ docComment !== null ? $ docComment ->getText () : null , $ nameScope ),
196+ $ this ->exportPhpDocNode ($ docComment !== null ? $ docComment ->getText () : null , $ namespaceUses ),
196197 $ node ->byRef ,
197198 NodeTypePrinter::printType ($ node ->returnType ),
198- $ this ->exportParameterNodes ($ node ->params , $ nameScope ),
199+ $ this ->exportParameterNodes ($ node ->params , $ namespaceUses ),
199200 $ this ->exportAttributeNodes ($ node ->attrGroups ),
200201 );
201202 }
@@ -238,7 +239,7 @@ public function resolve(Node $node, ExportedNameScope $nameScope): ?RootExported
238239 * @param Node\Param[] $params
239240 * @return ExportedParameterNode[]
240241 */
241- private function exportParameterNodes (array $ params , ExportedNameScope $ nameScope ): array
242+ private function exportParameterNodes (array $ params , NamespaceUses $ namespaceUses ): array
242243 {
243244 $ nodes = [];
244245 foreach ($ params as $ param ) {
@@ -267,32 +268,32 @@ private function exportParameterNodes(array $params, ExportedNameScope $nameScop
267268 $ param ->variadic ,
268269 $ param ->default !== null ,
269270 $ this ->exportAttributeNodes ($ param ->attrGroups ),
270- $ this ->exportPhpDocNode ($ docComment !== null ? $ docComment ->getText () : null , $ nameScope ),
271+ $ this ->exportPhpDocNode ($ docComment !== null ? $ docComment ->getText () : null , $ namespaceUses ),
271272 $ param ->flags ,
272273 );
273274 }
274275
275276 return $ nodes ;
276277 }
277278
278- private function exportPhpDocNode (?string $ text , ExportedNameScope $ nameScope ): ?ExportedPhpDocNode
279+ private function exportPhpDocNode (?string $ text , NamespaceUses $ namespaceUses ): ?ExportedPhpDocNode
279280 {
280281 if ($ text === null ) {
281282 return null ;
282283 }
283284
284- return new ExportedPhpDocNode ($ text , $ nameScope ->getNamespace (), $ nameScope ->getUses (), $ nameScope ->getConstUses ());
285+ return new ExportedPhpDocNode ($ text , $ namespaceUses ->getNamespace (), $ namespaceUses ->getUses (), $ namespaceUses ->getConstUses ());
285286 }
286287
287288 /**
288289 * @param Node\Stmt[] $statements
289290 * @return ExportedNode[]
290291 */
291- private function exportClassStatements (array $ statements , string $ namespacedName , ExportedNameScope $ nameScope ): array
292+ private function exportClassStatements (array $ statements , string $ namespacedName , NamespaceUses $ namespaceUses ): array
292293 {
293294 $ exportedNodes = [];
294295 foreach ($ statements as $ statement ) {
295- $ exportedNode = $ this ->exportClassStatement ($ statement , $ namespacedName , $ nameScope );
296+ $ exportedNode = $ this ->exportClassStatement ($ statement , $ namespacedName , $ namespaceUses );
296297 if ($ exportedNode === null ) {
297298 continue ;
298299 }
@@ -303,7 +304,7 @@ private function exportClassStatements(array $statements, string $namespacedName
303304 return $ exportedNodes ;
304305 }
305306
306- private function exportClassStatement (Node \Stmt $ node , string $ namespacedName , ExportedNameScope $ nameScope ): ?ExportedNode
307+ private function exportClassStatement (Node \Stmt $ node , string $ namespacedName , NamespaceUses $ namespaceUses ): ?ExportedNode
307308 {
308309 if ($ node instanceof ClassMethod) {
309310 if ($ node ->isAbstract () || $ node ->isFinal () || !$ node ->isPrivate ()) {
@@ -312,15 +313,15 @@ private function exportClassStatement(Node\Stmt $node, string $namespacedName, E
312313
313314 return new ExportedMethodNode (
314315 $ methodName ,
315- $ this ->exportPhpDocNode ($ docComment !== null ? $ docComment ->getText () : null , $ nameScope ),
316+ $ this ->exportPhpDocNode ($ docComment !== null ? $ docComment ->getText () : null , $ namespaceUses ),
316317 $ node ->byRef ,
317318 $ node ->isPublic (),
318319 $ node ->isPrivate (),
319320 $ node ->isAbstract (),
320321 $ node ->isFinal (),
321322 $ node ->isStatic (),
322323 NodeTypePrinter::printType ($ node ->returnType ),
323- $ this ->exportParameterNodes ($ node ->params , $ nameScope ),
324+ $ this ->exportParameterNodes ($ node ->params , $ namespaceUses ),
324325 $ this ->exportAttributeNodes ($ node ->attrGroups ),
325326 );
326327 }
@@ -353,7 +354,7 @@ private function exportClassStatement(Node\Stmt $node, string $namespacedName, E
353354
354355 return new ExportedPropertiesNode (
355356 $ names ,
356- $ this ->exportPhpDocNode ($ docComment !== null ? $ docComment ->getText () : null , $ nameScope ),
357+ $ this ->exportPhpDocNode ($ docComment !== null ? $ docComment ->getText () : null , $ namespaceUses ),
357358 NodeTypePrinter::printType ($ node ->type ),
358359 $ node ->isPublic (),
359360 $ node ->isPrivate (),
@@ -366,7 +367,7 @@ private function exportClassStatement(Node\Stmt $node, string $namespacedName, E
366367 $ node ->isPrivateSet (),
367368 $ virtual ,
368369 $ this ->exportAttributeNodes ($ node ->attrGroups ),
369- $ this ->exportPropertyHooks ($ node ->hooks , $ nameScope ),
370+ $ this ->exportPropertyHooks ($ node ->hooks , $ namespaceUses ),
370371 );
371372 }
372373
@@ -391,7 +392,7 @@ private function exportClassStatement(Node\Stmt $node, string $namespacedName, E
391392 $ node ->isPublic (),
392393 $ node ->isPrivate (),
393394 $ node ->isFinal (),
394- $ this ->exportPhpDocNode ($ docComment !== null ? $ docComment ->getText () : null , $ nameScope ),
395+ $ this ->exportPhpDocNode ($ docComment !== null ? $ docComment ->getText () : null , $ namespaceUses ),
395396 );
396397 }
397398
@@ -401,7 +402,7 @@ private function exportClassStatement(Node\Stmt $node, string $namespacedName, E
401402 return new ExportedEnumCaseNode (
402403 $ node ->name ->toString (),
403404 $ node ->expr !== null ? $ this ->exprPrinter ->printExpr ($ node ->expr ) : null ,
404- $ this ->exportPhpDocNode ($ docComment !== null ? $ docComment ->getText () : null , $ nameScope ),
405+ $ this ->exportPhpDocNode ($ docComment !== null ? $ docComment ->getText () : null , $ namespaceUses ),
405406 );
406407 }
407408
@@ -438,7 +439,7 @@ private function exportAttributeNodes(array $attributeGroups): array
438439 */
439440 private function exportPropertyHooks (
440441 array $ hooks ,
441- ExportedNameScope $ nameScope ,
442+ NamespaceUses $ namespaceUses ,
442443 ): array
443444 {
444445 $ nodes = [];
@@ -450,12 +451,12 @@ private function exportPropertyHooks(
450451 }
451452 $ nodes [] = new ExportedPropertyHookNode (
452453 $ hook ->name ->toString (),
453- $ this ->exportPhpDocNode ($ docComment !== null ? $ docComment ->getText () : null , $ nameScope ),
454+ $ this ->exportPhpDocNode ($ docComment !== null ? $ docComment ->getText () : null , $ namespaceUses ),
454455 $ hook ->byRef ,
455456 $ hook ->body === null ,
456457 $ hook ->isFinal (),
457458 $ hook ->body instanceof Expr,
458- $ this ->exportParameterNodes ($ hook ->params , $ nameScope ),
459+ $ this ->exportParameterNodes ($ hook ->params , $ namespaceUses ),
459460 $ this ->exportAttributeNodes ($ hook ->attrGroups ),
460461 );
461462 }
0 commit comments