@@ -220,20 +220,20 @@ public function createTypeLink(
220220 } elseif ($ type instanceof Type) {
221221 if ($ type instanceof Compound) {
222222 $ innerTypes = TypeHelper::getTypesByAggregatedType ($ type );
223- $ links [] = $ this ->createTypeLink ($ innerTypes , $ context , $ title , $ options );
223+ $ links [] = $ this ->createTypeLink ($ innerTypes , $ context , $ title , $ options, $ currentTypeDoc );
224224 continue ;
225225 }
226226
227227 if ($ type instanceof ConditionalForParameter || $ type instanceof Conditional) {
228228 $ possibleTypes = TypeHelper::getPossibleTypesByConditionalType ($ type );
229- $ links [] = $ this ->createTypeLink ($ possibleTypes , $ context , $ title , $ options );
229+ $ links [] = $ this ->createTypeLink ($ possibleTypes , $ context , $ title , $ options, $ currentTypeDoc );
230230 continue ;
231231 }
232232
233233 if ($ type instanceof Intersection) {
234234 $ innerTypes = TypeHelper::getTypesByAggregatedType ($ type );
235235 $ innerTypesLinks = array_map (
236- fn (Type $ innerType ) => $ this ->createTypeLink ($ innerType , $ context , $ title , $ options ),
236+ fn (Type $ innerType ) => $ this ->createTypeLink ($ innerType , $ context , $ title , $ options, $ currentTypeDoc ),
237237 $ innerTypes
238238 );
239239 $ links [] = implode ('& ' , $ innerTypesLinks );
@@ -247,7 +247,7 @@ public function createTypeLink(
247247 }
248248
249249 if ($ type instanceof Array_ && substr ((string ) $ type , -3 , 3 ) === ')[] ' ) {
250- $ arrayTypesLinks = $ this ->createTypeLink ($ type ->getValueType (), $ context , $ title , $ options );
250+ $ arrayTypesLinks = $ this ->createTypeLink ($ type ->getValueType (), $ context , $ title , $ options, $ currentTypeDoc );
251251 $ links [] = "( {$ arrayTypesLinks })[] " ;
252252 continue ;
253253 }
@@ -257,7 +257,7 @@ public function createTypeLink(
257257 if ($ valueType instanceof Object_ && $ valueType ->getFqsen () !== null ) {
258258 $ templateType = $ this ->getTemplateType ((string ) $ valueType ->getFqsen (), $ context );
259259 if ($ templateType !== null ) {
260- $ typeLink = $ this ->createTypeLink ($ templateType , $ context , $ title , $ options );
260+ $ typeLink = $ this ->createTypeLink ($ templateType , $ context , $ title , $ options, $ currentTypeDoc );
261261 $ links [] = $ templateType instanceof Compound ? "( {$ typeLink })[] " : "{$ typeLink }[] " ;
262262 continue ;
263263 }
@@ -268,14 +268,14 @@ public function createTypeLink(
268268 }
269269
270270 if ($ type instanceof ArrayShape) {
271- $ itemsLinks = $ this ->createLinksByShapeItems ($ type ->getItems (), $ context , $ title , $ options );
271+ $ itemsLinks = $ this ->createLinksByShapeItems ($ type ->getItems (), $ context , $ title , $ options, $ currentTypeDoc );
272272 $ mainTypeLink = $ this ->generateLink ('array ' , self ::PHPSTAN_TYPE_BASE_URL . 'array-shapes ' , $ options );
273273 $ links [] = $ mainTypeLink . '{ ' . implode (', ' , $ itemsLinks ) . '} ' ;
274274 continue ;
275275 }
276276
277277 if ($ type instanceof ObjectShape) {
278- $ itemsLinks = $ this ->createLinksByShapeItems ($ type ->getItems (), $ context , $ title , $ options );
278+ $ itemsLinks = $ this ->createLinksByShapeItems ($ type ->getItems (), $ context , $ title , $ options, $ currentTypeDoc );
279279 $ mainTypeLink = $ this ->generateLink ('object ' , self ::PHPSTAN_TYPE_BASE_URL . 'object-shapes ' , $ options );
280280 $ links [] = $ mainTypeLink . '{ ' . implode (', ' , $ itemsLinks ) . '} ' ;
281281 continue ;
@@ -291,7 +291,7 @@ public function createTypeLink(
291291 continue ;
292292 }
293293
294- if (($ link = $ this ->createLinkByTypeWithGenerics ($ type , $ context , $ title , $ options )) !== null ) {
294+ if (($ link = $ this ->createLinkByTypeWithGenerics ($ type , $ context , $ title , $ options, $ currentTypeDoc )) !== null ) {
295295 $ links [] = $ link ;
296296 continue ;
297297 }
@@ -306,7 +306,7 @@ public function createTypeLink(
306306 }
307307
308308 if (($ templateType = $ this ->getTemplateType ($ fqsen , $ context )) !== null ) {
309- $ links [] = $ this ->createTypeLink ($ templateType , $ context , $ title , $ options );
309+ $ links [] = $ this ->createTypeLink ($ templateType , $ context , $ title , $ options, $ currentTypeDoc );
310310 continue ;
311311 }
312312
@@ -607,8 +607,13 @@ private function getTypeDocByQualifiedClassName(string $className, ?BaseDoc $con
607607 * @param ShapeItem[] $items
608608 * @return string[]
609609 */
610- private function createLinksByShapeItems (array $ items , ?BaseDoc $ context , ?string $ title , array $ options ): array
611- {
610+ private function createLinksByShapeItems (
611+ array $ items ,
612+ ?BaseDoc $ context ,
613+ ?string $ title ,
614+ array $ options ,
615+ ?TypeDoc $ currentTypeDoc
616+ ): array {
612617 $ links = [];
613618
614619 foreach ($ items as $ item ) {
@@ -618,10 +623,10 @@ private function createLinksByShapeItems(array $items, ?BaseDoc $context, ?strin
618623 '%s%s: %s ' ,
619624 $ itemKey ,
620625 $ item ->isOptional () ? '? ' : '' ,
621- $ this ->createTypeLink ($ item ->getValue (), $ context , $ title , $ options )
626+ $ this ->createTypeLink ($ item ->getValue (), $ context , $ title , $ options, $ currentTypeDoc )
622627 );
623628 } else {
624- $ links [] = $ this ->createTypeLink ($ item ->getValue (), $ context , $ title , $ options );
629+ $ links [] = $ this ->createTypeLink ($ item ->getValue (), $ context , $ title , $ options, $ currentTypeDoc );
625630 }
626631 }
627632
@@ -635,15 +640,21 @@ private function createLinkByTypeWithGenerics(
635640 Type $ type ,
636641 ?BaseDoc $ context ,
637642 ?string $ title ,
638- array $ options
643+ array $ options ,
644+ ?TypeDoc $ currentTypeDoc
639645 ): ?string {
640646 /**
641647 * @param Type[] $genericTypes
642648 */
643- $ generateLink = function (Type $ mainType , array $ genericTypes ) use ($ context , $ title , $ options ): string {
649+ $ generateLink = function (Type $ mainType , array $ genericTypes ) use (
650+ $ context ,
651+ $ title ,
652+ $ options ,
653+ $ currentTypeDoc
654+ ): string {
644655 $ genericTypesLinks = $ this ->createTypeLinksByTypes ($ genericTypes , $ context , $ title , $ options );
645656 $ mainTypeLinkOptions = array_merge ($ options , ['forcePhpStanLink ' => true ]);
646- $ mainTypeLink = $ this ->createTypeLink ($ mainType , $ context , $ title , $ mainTypeLinkOptions );
657+ $ mainTypeLink = $ this ->createTypeLink ($ mainType , $ context , $ title , $ mainTypeLinkOptions, $ currentTypeDoc );
647658 return "{$ mainTypeLink }< " . implode (', ' , $ genericTypesLinks ) . '> ' ;
648659 };
649660
0 commit comments