2424use TypePHP \Internal \ClassNameValidator ;
2525use TypePHP \Internal \ErrorFactory ;
2626use TypePHP \Internal \ErrorMessage ;
27+ use TypePHP \Internal \StubManager ;
2728use WeakMap ;
2829
2930/**
@@ -168,10 +169,11 @@ public static function getTemplateVariances(object $instance): array
168169 $ className = \get_class ($ instance );
169170
170171 try {
172+ $ stubDoc = StubManager ::getClassDoc ($ className );
171173 $ ref = new \ReflectionClass ($ className );
172- $ classDoc = $ ref ->getDocComment ();
174+ $ classDoc = $ stubDoc ?? $ ref ->getDocComment ();
173175
174- if ($ classDoc !== false ) {
176+ if ($ classDoc !== false && $ classDoc !== null ) {
175177 [$ phpDocParser , $ lexer ] = self ::getPhpDocParserComponents ();
176178
177179 $ classTokens = new TokenIterator ($ lexer ->tokenize ($ classDoc ));
@@ -309,8 +311,11 @@ private static function collectHierarchyTemplatesAndVariances(\ReflectionClass $
309311 $ classVariances = [];
310312
311313 foreach ($ classHierarchy as $ hierClass ) {
312- $ classDoc = $ hierClass ->getDocComment ();
313- if ($ classDoc === false ) {
314+ $ hierClassName = $ hierClass ->getName ();
315+ $ stubDoc = StubManager ::getClassDoc ($ hierClassName );
316+ $ classDoc = $ stubDoc ?? $ hierClass ->getDocComment ();
317+
318+ if ($ classDoc === false || $ classDoc === null ) {
314319 continue ;
315320 }
316321
@@ -402,7 +407,7 @@ private static function bindSingleTemplateArgument(
402407
403408 /**
404409 * Resolves and binds parent class (@extends), interface (@implements), and trait (@use) template mappings.
405- * Respects Vendor Isolation by skipping docblocks from excluded vendor ancestor files.
410+ * Respects Vendor Isolation by skipping docblocks from excluded vendor ancestor files unless stubbed .
406411 */
407412 public static function resolveInheritedTemplates (object $ instance , string $ targetClassName ): void
408413 {
@@ -415,8 +420,10 @@ public static function resolveInheritedTemplates(object $instance, string $targe
415420
416421 foreach ($ classHierarchy as $ hierClass ) {
417422 $ fileName = $ hierClass ->getFileName ();
423+ $ hierClassName = $ hierClass ->getName ();
424+ $ stubDoc = StubManager ::getClassDoc ($ hierClassName );
418425
419- if ($ hierClass ->getName () !== $ actualClassName && FileFilter ::isFileExcluded ($ fileName !== false ? $ fileName : null )) {
426+ if ($ stubDoc === null && $ hierClass ->getName () !== $ actualClassName && FileFilter ::isFileExcluded ($ fileName !== false ? $ fileName : null )) {
420427 continue ;
421428 }
422429
@@ -457,8 +464,9 @@ private static function collectDocsForClassHierarchyMember(\ReflectionClass $hie
457464 {
458465 $ docs = [];
459466
460- $ classDoc = $ hierClass ->getDocComment ();
461- if ($ classDoc !== false ) {
467+ $ stubDoc = StubManager ::getClassDoc ($ hierClass ->getName ());
468+ $ classDoc = $ stubDoc ?? $ hierClass ->getDocComment ();
469+ if ($ classDoc !== false && $ classDoc !== null ) {
462470 $ docs [] = $ classDoc ;
463471 }
464472
@@ -492,10 +500,11 @@ private static function bindInheritedGenericTag(
492500 }
493501
494502 try {
503+ $ stubDoc = StubManager ::getClassDoc ($ parentName );
495504 $ parentRef = new \ReflectionClass ($ parentName );
496- $ parentDoc = $ parentRef ->getDocComment ();
505+ $ parentDoc = $ stubDoc ?? $ parentRef ->getDocComment ();
497506
498- if ($ parentDoc === false ) {
507+ if ($ parentDoc === false || $ parentDoc === null ) {
499508 return ;
500509 }
501510
0 commit comments