phpdocumentor/reflection
Static PHP code reflection library that parses files without executing them. Builds an object graph of your project’s structure, including DocBlocks. Can analyze code from PHP 5.2 up to your installed version; suitable for reflecting whole files or projects.
routes/web.php) to generate call graphs or dependency trees.@Route, @Middleware, @Test). This package supports PHP 8+ attributes, enabling deep analysis of Laravel’s metadata-driven features.eval(), create_function()).phpdocumentor/reflection).ProjectFactory instantiation).Illuminate\Foundation\Application).booted event) to trigger analysis post-initialization.process facade or spatie/fork).| Risk Area | Mitigation Strategy |
|---|---|
| False Positives | Validate outputs against known Laravel patterns (e.g., facade resolutions). |
| Version Skew | Pin to a stable release (e.g., 6.6.0) and test against Laravel’s PHP version. |
| Attribute Parsing | Test edge cases (e.g., nested attributes, custom Laravel attributes). |
| Dependency Bloat | Audit phpparser and type-resolver for Laravel compatibility (e.g., no conflicts). |
| Tooling Conflicts | Ensure no overlap with Laravel’s built-in reflection (e.g., app()->make()). |
ServiceProvider classes; for security, prioritize attribute scanning.app/ (risk: incomplete)?Route::get()) or macroable classes?composer require phpdocumentor/reflection).php artisan reflect command.ReflectionServiceProvider to cache analysis results.assertClassUsesAttribute()).app/Http/Controllers).ProjectFactory to analyze files and log results to storage/logs/reflection.log.vendor/).$factory->addReducer(new class implements Reducer {
public function reduce(Node $node) {
if ($node instanceof ClassLike && str_starts_with($node->getFqsen(), 'App\\')) {
return $node; // Keep Laravel classes
}
return null; // Skip others
}
});
cache()->remember())./api/reflection/classes/{class}).| Component | Compatibility Notes |
|---|---|
| Laravel Core | No conflicts; uses static analysis only. |
| Third-Party Packages | Risk if packages use eval() or obfuscation. Test with laravel-debugbar. |
| PHP Extensions | None required; pure PHP implementation. |
| Database | Optional: Store results in reflection table (e.g., class metadata, attributes). |
vendor/, node_modules/, and generated files (e.g., bootstrap/cache/).ProjectFactory with Laravel-aware settings (e.g., parser version).spatie/fork).$factory = ProjectFactory::createInstance();
$files = FileLocator::locateFiles(['app/', 'config/'], ['*.php']);
$project = $factory->create('Laravel App', $files);
ReflectionAnalyzed event) for downstream tools.phpparser and type-resolver for breaking changes (e.g., PHP 9.0 support).README.md under docs/reflection/.@Route annotations for API documentation.phpDocumentor\Reflection\Exception handling to log parsing errors.try {
$project = $factory->create('App', $files);
} catch (ParseErrorException $e) {
report($e); // Use Laravel’s error reporting
}
vendor/ → Add path exclusion.@Middleware, @Route, etc.main branch).cache() or Redis (TTL: 24h).git diff).sysgetloadavg().reflection:analyze job).
How can I help you explore Laravel packages today?