Create API documentation from DocBlock with PHPDocumentor

Code
<?php

use phpDocumentor\Reflection\DocBlock;

/**
 * A class that does nothing special
 *
 * This class has no purpose like any
 * other example class. Just ignore it.
 */
class Foo
{
    /**
     * This method does something
     *
     * It appends the value of $str to
     * getBar() and returns the result.
     * Cool, isn't it?
     *
     * @param string $str string to append
     * @return string new string value
     */
    public function doSomething($str)
    {
        return $this->getBar() . $str;
    }
    
    /**
     * Get bar value
     *
     * Returns hardcoded bar value.
     * Everyone needs a bar
     *
     * @return string returns only bar
     */
    private function getBar()
    {
        return 'bar';
    }
}

$class = new ReflectionClass('Foo');
$phpDoc = new DocBlock($class->getName());

echo $phpDoc->getContext() . PHP_EOL . PHP_EOL;

echo '<i>Methods comments:</i>' . PHP_EOL;
foreach ($class->getMethods() as $method) {
    $methodDoc = new DocBlock($method->getName());
    
    echo '<h3>' . $method->getName() . '</h3>';
    echo '<h4>' . $methodDoc->getSummary() . '</h4>';
    echo $methodDoc->getDescription() .
        PHP_EOL . PHP_EOL;
    
    if ($methodDoc->hasTag('param')) {
        foreach ($methodDoc->getTagsByName('param') as $t) {
            echo '<b>' . $t->getVariableName() . '</b>' .
                ' is of type ' . $t->getType() .
                ': <i>' . $t->getDescription() . '</i>' .
                PHP_EOL;
        }
    }
    
    if ($methodDoc->hasTag('return')) {
        foreach ($methodDoc->getTagsByName('return') as $t) {
            echo 'Return value is of type<b> ' . $t->getType() . '</b>' .
                ': <i>' . $t->getDescription() . '</i>' . PHP_EOL;
        }
    }
}
Result
Methods comments:

doSomething

doSomething



getBar

getBar

Used Versions
PHP 8.3, Laminas MVC 3.2, Symfony 5.2, Laravel 8.28, PHPUnit 9.5, Doctrine ORM 2.8