phpowermove/docblock
Parse, create, and edit PHP DocBlocks with a simple API. Build Docblock instances from strings or reflection, read and filter tags, add tags via fluent helpers, and render back to formatted docblock text for code generation and tooling.
Install the package via Composer: composer require phpowermove/docblock. Start by parsing a simple DocBlock using the DocBlock class:
use PhpPowerMove\DocBlock\DocBlock;
$doc = new DocBlock('/** @param string $name @return void */');
$tags = $doc->getTags(); // Returns array of tag objects
$param = $tags['param'][0] ?? null; // First @param tag
The shortest path to value is integrating it into reflection-based workflows—e.g., when analyzing method signatures for validation or documentation tools. Begin by examining the DocBlock constructor and its getSummary(), getDescription(), and getTags() methods in the source.
ReflectionMethod/ReflectionClass to hydrate custom metadata. Example: Extract @todo tags from controller actions for a CLI task list.Tag::getTypes() to access typed metadata (e.g., @var int<1,10>) for schema validation or schema inference in CLI or API tools.Tag objects to implement domain-specific annotations (e.g., @route("/users")) without bloating core logic.@return tags, enforce consistent @throws usage, or validate parameter naming.getTags() returns an associative array keyed by tag name, not by position—even single tags like @param are arrays. Always check isset($tags['param']) or use null coalescing.*) are stripped, but inconsistent spacing (e.g., mixed tabs/spaces) can break tag detection; run DocBlock::normalize() if pre-processing raw comments.@param, @var, etc., it does not parse complex union types (int|string) into structured data—you’ll need to split them manually or integrate with a type parser.@method Support: The library ignores @method by default. Override Tag::create() in a custom DocBlockFactory if you need method-level metadata.DocBlock instance and call reset() between invocations to avoid memory churn.How can I help you explore Laravel packages today?