33namespace PHPStan \Type ;
44
55use Closure ;
6- use PhpParser \Comment \Doc ;
76use PhpParser \Node ;
87use PHPStan \Analyser \NameScope ;
98use PHPStan \BetterReflection \Util \GetLastDocComment ;
@@ -435,7 +434,12 @@ function (Node $node) use ($fileName, $lookForTrait, $phpDocNodeMap, &$traitFoun
435434 }
436435
437436 $ traitFound = true ;
438- $ typeAliasStack [] = $ this ->getTypeAliasesMap ($ node ->getDocComment ());
437+ $ traitNameScopeKey = $ this ->getNameScopeKey ($ originalClassFileName , $ classStack [count ($ classStack ) - 1 ] ?? null , $ lookForTrait , null );
438+ if (array_key_exists ($ traitNameScopeKey , $ phpDocNodeMap )) {
439+ $ typeAliasStack [] = $ this ->getTypeAliasesMap ($ phpDocNodeMap [$ traitNameScopeKey ]);
440+ } else {
441+ $ typeAliasStack [] = [];
442+ }
439443 $ functionStack [] = null ;
440444 } else {
441445 if ($ node ->name === null ) {
@@ -453,7 +457,12 @@ function (Node $node) use ($fileName, $lookForTrait, $phpDocNodeMap, &$traitFoun
453457 $ className = ltrim (sprintf ('%s \\%s ' , $ namespace , $ node ->name ->name ), '\\' );
454458 }
455459 $ classStack [] = $ className ;
456- $ typeAliasStack [] = $ this ->getTypeAliasesMap ($ node ->getDocComment ());
460+ $ classNameScopeKey = $ this ->getNameScopeKey ($ originalClassFileName , $ className , $ lookForTrait , null );
461+ if (array_key_exists ($ classNameScopeKey , $ phpDocNodeMap )) {
462+ $ typeAliasStack [] = $ this ->getTypeAliasesMap ($ phpDocNodeMap [$ classNameScopeKey ]);
463+ } else {
464+ $ typeAliasStack [] = [];
465+ }
457466 $ functionStack [] = null ;
458467 }
459468 } elseif ($ node instanceof Node \Stmt \ClassMethod) {
@@ -716,13 +725,8 @@ static function (Node $node, $callbackResult) use (&$namespace, &$functionStack,
716725 /**
717726 * @return array<string, true>
718727 */
719- private function getTypeAliasesMap (? Doc $ docComment ): array
728+ private function getTypeAliasesMap (PhpDocNode $ phpDocNode ): array
720729 {
721- if ($ docComment === null ) {
722- return [];
723- }
724-
725- $ phpDocNode = $ this ->phpDocStringResolver ->resolve ($ docComment ->getText ());
726730 $ nameScope = new NameScope (null , []);
727731
728732 $ aliasesMap = [];
0 commit comments