Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Reflection Laravel Package

phpdocumentor/reflection

PHPDoc reflection library used by phpDocumentor to parse docblocks and reflect types, namespaces, and symbols from PHP code. Helps tools extract documentation and metadata without executing code, powering static analysis and doc generation workflows.

View on GitHub
Deep Wiki
Context7

Getting Started

Start by installing the package via Composer: composer require phpdocumentor/reflection. Unlike phpdocumentor/reflection-docblock, this is a newer, modern library (v4+) designed for static analysis of PHP codebases—ideal for tools like linters, IDEs, or documentation generators. The core entry points are File, Folder, and ProjectBuilder. To begin analyzing a single file:

use phpDocumentor\Reflection\ProjectBuilder;
use phpDocumentor\Reflection\Fixture\File;

$projectBuilder = new ProjectBuilder();
$project = $projectBuilder->buildFromDirectory(__DIR__ . '/src');
foreach ($project->getFiles() as $file) {
    echo "Analyzed file: " . $file->getFilename() . "\n";
}

Read the README and the API docs for detailed usage.

Implementation Patterns

  • Project-wide analysis: Use ProjectBuilder to build a complete model of a PHP codebase, enabling cross-file analysis (e.g., finding all usages of a class across a project).
  • AST-level introspection: Access raw AST nodes via $file->getStatements() for custom static analysis rules (e.g., detecting code smells).
  • Custom data extraction: Build lightweight tools that extract type hints, docblocks, or class structures for reporting or linting—useful in CI pipelines.
  • Integration with Symfony/CLI tools: Wrap analysis in a Symfony Command for custom linters or documentation generators.
  • Caching: Leverage FileListCollector and serialized project caches to speed up repeated analysis in long-running tools.

Gotchas and Tips

  • PHP version support: Requires PHP 8.1+; ensure your tooling aligns with this. Old syntax (e.g., legacy PHP 7 code) may cause parse failures—add custom error handlers or skip non-compliant files.
  • Performance: Full project builds can be memory-heavy. Use ProjectBuilder::buildFromDirectory() with a filter callback to limit scope, or analyze files incrementally.
  • Empty getNamespaces(): If your project has no declared namespace, getNamespaces() returns empty. Always check $file->getNamespaceName() for null or empty strings.
  • Docblock parsing quirks: Not all docblock structures are standardized. Use File->getDocBlock() cautiously—test with a variety of comment styles.
  • Extensibility: Extend ProjectBuilder or implement custom NodeVisitors to inject domain-specific analysis logic (e.g., enforce internal naming conventions).
  • Debugging: Enable ErrorHandler::disable() to prevent silent parse failures during development—actual errors get thrown as ParseError exceptions.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport