phpdoc-parser
phpdoc-parser copied to clipboard
Example of how to render classes PHPDoc
Hey Jasny,
Not really an issue, but wanted to share some code for those looking to get phpdoc for classes in an array.
This does get the default properties and methods available in the class provided. Could definitely use some tweaking
I didn't see any example on your site, so decided I may be able to figure it out. Now I'm seeing its going to take a lot longer than I expected to create markdown files from some classes with PHPDoc comments, but I might circle back around to it later.
use Jasny\PhpdocParser\PhpdocParser;
use Jasny\PhpdocParser\Set\PhpDocumentor;
use Jasny\PhpdocParser\Tag\Summery;
include 'vendor/autoload.php';
$cls = new ReflectionClass('Jasny\PhpdocParser\PhpdocParser');
$doc = $cls->getDocComment();
$tags = PhpDocumentor::tags()->with([new Summery()]);
$parser = new PhpdocParser($tags);
$meta = $parser->parse($doc);
$foundProperties = $cls->getDefaultProperties();
$getMethods = $cls->getMethods();
$foundMethods = [];
foreach($getMethods as $methodAry){
$docMethod = $cls->getMethod($methodAry->name)->getDocComment();
$foundMethods[$methodAry->name] = $parser->parse($docMethod);
}
echo print_r($meta,1).PHP_EOL
.print_r($foundProperties,1).PHP_EOL
.print_r($foundMethods,1).PHP_EOL;