spatie/php-structure-discoverer
Discover PHP classes, interfaces, traits, and enums that match conditions (e.g., implement an interface) across your project. Fast scanning with built-in caching and rich metadata—ideal for auto-registration, tooling, and framework integrations.
Codebase Discovery & Metadata-Driven Features:
Build vs. Buy for Custom Tooling:
Serializable or using @Cacheable).get_declared_classes() hacks).Performance Optimization for Large Codebases:
Laravel-Specific Use Cases:
Illuminate\Contracts\Auth\Authenticatable without manual configuration.Model subclasses to auto-generate migrations for new fields.tests/Unit/ to dynamically generate test reports.Roadmap for "Self-Healing" Codebases:
Avoid if:
get_declared_classes() suffices.Look Elsewhere if:
Carbon"): Combine with PHP Parser or Nikic’s PHP-Reflection.*"This package lets us automate codebase introspection—like a ‘Google for our PHP classes’—to build tools that save dev time. For example:
- Auto-generate API docs by scanning all
@ApiResourceclasses.- Cut migration time by auto-discovering all Eloquent models.
- Reduce tech debt by flagging unused interfaces or broken inheritance. It’s low-risk (MIT license, battle-tested by Spatie), scalable (caching + parallel scans), and future-proof for tools like AI-assisted refactoring. Investment: ~1 dev day to integrate; ROI: weeks of saved manual work."*
*"This is a Swiss Army knife for codebase metadata. Key wins:
- Replace ad-hoc scripts: No more
grep/findhacks to list classes implementingShouldBeCached. Just:Discover::in(app_path())->implementing(ShouldBeCached::class)->get();- Build reusable infrastructure: Cache discovery results for CLI tools, tests, or deploy scripts.
- Leverage Laravel’s ecosystem: Works seamlessly with Artisan commands, caching, and config.
- Performance out of the box: Parallel scans + caching make it fast in production.
Tradeoffs:
- Not a silver bullet for deep static analysis (e.g., method-level logic).
- Requires initial setup (configuring directories, cache drivers).
Proposal: Pilot this for one high-impact use case (e.g., auto-generating model factories) to validate ROI before scaling."*
How can I help you explore Laravel packages today?