@@ -188,18 +188,19 @@ public function getValueString(mixed $value) : string
188
188
189
189
/**
190
190
* Format comments without indentation
191
+ * @template T of \ReflectionClass
192
+ * @param \ReflectionMethod | \ReflectionClass<T> | null $reflection
191
193
*/
192
- protected function formatComments (?\phpDocumentor \Reflection \DocBlock $ docBlock , ? \ReflectionMethod $ reflectionMethod = null ) : string
194
+ protected function formatComments (?\phpDocumentor \Reflection \DocBlock $ docBlock , \ReflectionMethod | \ ReflectionClass | null $ reflection = null ) : string
193
195
{
194
196
if (! $ docBlock )
195
197
{
196
198
return '' ;
197
199
}
198
200
199
201
$ container = new \PHPFUI \Container ();
200
-
201
- $ container ->add ($ this ->parsedown ->text ($ this ->getInheritedText ($ docBlock , $ reflectionMethod , 'getSummary ' )));
202
- $ desc = $ this ->getInheritedText ($ docBlock , $ reflectionMethod , 'getDescription ' );
202
+ $ container ->add ($ this ->parsedown ->text ($ this ->getInheritedText ($ docBlock , $ reflection , 'getSummary ' )));
203
+ $ desc = $ this ->getInheritedText ($ docBlock , $ reflection );
203
204
204
205
if ($ desc )
205
206
{
@@ -211,9 +212,9 @@ protected function formatComments(?\phpDocumentor\Reflection\DocBlock $docBlock,
211
212
212
213
$ tags = $ docBlock ->getTags ();
213
214
// if we are in a method, inheritdoc makes sense, and we should get the correct doc block comments
214
- if ($ reflectionMethod )
215
+ if ($ reflection instanceof \ReflectionMethod )
215
216
{
216
- $ tags = $ this ->getInheritedDocBlock ($ tags , $ reflectionMethod );
217
+ $ tags = $ this ->getInheritedDocBlock ($ tags , $ reflection );
217
218
}
218
219
219
220
if ($ tags )
@@ -288,7 +289,7 @@ protected function formatComments(?\phpDocumentor\Reflection\DocBlock $docBlock,
288
289
$ ul ->addItem (new \PHPFUI \ListItem ($ this ->getColor ('name ' , $ name ) . ' ' . $ this ->getColor ('description ' , $ body )));
289
290
}
290
291
291
- $ attributes = $ this ->getAttributes ($ reflectionMethod );
292
+ $ attributes = $ this ->getAttributes ($ reflection );
292
293
293
294
foreach ($ attributes as $ attribute )
294
295
{
@@ -367,7 +368,7 @@ protected function getColor(string $class, string $name) : string
367
368
/**
368
369
* Get comments indented
369
370
*/
370
- protected function getComments (?\phpDocumentor \Reflection \DocBlock $ docBlock , ?\ReflectionMethod $ reflectionMethod = null ) : string
371
+ protected function getComments (?\phpDocumentor \Reflection \DocBlock $ docBlock , ?\ReflectionMethod $ reflection = null ) : string
371
372
{
372
373
if (! $ docBlock )
373
374
{
@@ -379,7 +380,7 @@ protected function getComments(?\phpDocumentor\Reflection\DocBlock $docBlock, ?\
379
380
$ cell1 ->add (' ' );
380
381
$ gridX ->add ($ cell1 );
381
382
$ cell11 = new \PHPFUI \Cell (11 );
382
- $ cell11 ->add ($ this ->formatComments ($ docBlock , $ reflectionMethod ));
383
+ $ cell11 ->add ($ this ->formatComments ($ docBlock , $ reflection ));
383
384
$ gridX ->add ($ cell11 );
384
385
385
386
return $ gridX ;
@@ -417,11 +418,15 @@ protected function getHtmlClass(string $class) : string
417
418
return \str_replace ('\\' , '- ' , $ class );
418
419
}
419
420
420
- protected function getInheritedText (\phpDocumentor \Reflection \DocBlock $ docBlock , ?\ReflectionMethod $ reflectionMethod = null , string $ textType = 'getDescription ' ) : string
421
+ /**
422
+ * @template T of \ReflectionClass
423
+ * @param \ReflectionMethod | \ReflectionClass<T> | null $reflection
424
+ */
425
+ protected function getInheritedText (\phpDocumentor \Reflection \DocBlock $ docBlock , \ReflectionMethod | \ReflectionClass | null $ reflection = null , string $ textType = 'getDescription ' ) : string
421
426
{
422
427
$ summary = $ docBlock ->{$ textType }();
423
428
424
- if (! $ reflectionMethod )
429
+ if (! $ reflection || ' getSummary ' == $ textType )
425
430
{
426
431
return $ summary ;
427
432
}
@@ -430,35 +435,54 @@ protected function getInheritedText(\phpDocumentor\Reflection\DocBlock $docBlock
430
435
431
436
foreach ($ tags as $ index => $ tag )
432
437
{
433
- $ pos = \stripos ($ tag ->getName (), 'inheritdoc ' );
434
-
435
- if (false !== $ pos && 0 <= $ pos )
438
+ if (false !== \stripos ($ tag ->getName (), 'inheritdoc ' ))
436
439
{
437
- $ reflectionClass = $ reflectionMethod ->getDeclaringClass ();
438
- $ parent = $ reflectionClass ->getParentClass ();
439
-
440
- while ($ parent )
440
+ if ($ reflection instanceof \ReflectionMethod)
441
441
{
442
- try
443
- {
444
- $ method = $ parent ->getMethod ($ reflectionMethod ->name );
445
- }
446
- catch (\Throwable )
442
+ $ reflectionClass = $ reflection ->getDeclaringClass ();
443
+ $ parent = $ reflectionClass ->getParentClass ();
444
+
445
+ while ($ parent )
447
446
{
448
- $ method = null ;
447
+ try
448
+ {
449
+ $ method = $ parent ->getMethod ($ reflection ->name );
450
+ }
451
+ catch (\Throwable )
452
+ {
453
+ $ method = null ;
454
+ }
455
+
456
+ if ($ method )
457
+ {
458
+ $ docBlock = $ this ->getDocBlock ($ method );
459
+
460
+ if ($ docBlock )
461
+ {
462
+ return $ this ->getInheritedText ($ docBlock , $ method ) . $ summary ;
463
+ }
464
+ }
465
+ $ parent = $ parent ->getParentClass ();
449
466
}
450
467
451
- if ($ method )
468
+ break ;
469
+ }
470
+
471
+
472
+ $ parent = $ reflection ->getParentClass ();
473
+
474
+ while ($ parent )
452
475
{
453
- $ docBlock = $ this -> getDocBlock ( $ method );
476
+ $ comments = $ parent -> getDocComment ( );
454
477
455
- if ($ docBlock )
478
+ if ($ comments )
456
479
{
457
- return $ this ->getInheritedText ($ docBlock , $ method , $ textType ) . $ summary ;
480
+ $ comments = \str_replace ('{@inheritdoc} ' , '@inheritdoc ' , $ comments );
481
+ $ docblock = $ this ->factory ->create ($ comments );
482
+ $ summary = $ this ->formatComments ($ docblock , $ parent ) . $ summary ;
458
483
}
484
+ $ parent = $ parent ->getParentClass ();
459
485
}
460
- $ parent = $ parent ->getParentClass ();
461
- }
462
486
463
487
break ;
464
488
}
@@ -469,23 +493,25 @@ protected function getInheritedText(\phpDocumentor\Reflection\DocBlock $docBlock
469
493
470
494
/**
471
495
* @param array<int, \phpDocumentor\Reflection\DocBlock\Tag> $tags
496
+ * @template T of \ReflectionClass
497
+ * @param \ReflectionMethod | \ReflectionClass<T> | null $reflection
472
498
*
473
499
* @return array<int, \phpDocumentor\Reflection\DocBlock\Tag>
474
500
*/
475
- protected function getInheritedDocBlock (array $ tags , \ReflectionMethod $ reflectionMethod ) : array
501
+ protected function getInheritedDocBlock (array $ tags , \ReflectionMethod | \ ReflectionClass | null $ reflection ) : array
476
502
{
477
503
foreach ($ tags as $ index => $ tag )
478
504
{
479
- if (0 > = \stripos ($ tag ->getName (), 'inheritdoc ' ))
505
+ if (false != = \stripos ($ tag ->getName (), 'inheritdoc ' ))
480
506
{
481
- $ reflectionClass = $ reflectionMethod ->getDeclaringClass ();
507
+ $ reflectionClass = ( $ reflection instanceof \ReflectionMethod) ? $ reflection ->getDeclaringClass () : $ reflection ;
482
508
$ parent = $ reflectionClass ->getParentClass ();
483
509
484
510
while ($ parent )
485
511
{
486
512
try
487
513
{
488
- $ method = $ parent ->getMethod ($ reflectionMethod ->name );
514
+ $ method = $ parent ->getMethod ($ reflection ->name );
489
515
}
490
516
catch (\Throwable )
491
517
{
0 commit comments