php-stubs/generator
Generate PHP stub files from your codebase for better IDE autocomplete, static analysis, and documentation. php-stubs/generator scans sources and produces lightweight stubs suitable for packages and frameworks, helping consumers get accurate type hints without shipping full sources.
php-stubs/generator package excels in enhancing developer productivity within Laravel ecosystems by generating IDE-compatible stubs for untyped, legacy, or third-party PHP code. It aligns with Laravel’s dynamic and loosely typed nature while enabling static analysis and IDE autocompletion without manual PHPDoc maintenance.
__call, __get) or eloquent relationships.composer require php-stubs/generator.composer install or PRs.--visitor flag for complex logic).Illuminate\Support\Facades\Facade) are already stubbed, but custom packages may require manual tuning.| Risk Area | Severity | Mitigation Strategy |
|---|---|---|
| Stub Inaccuracy | High | Validate stubs via unit tests or property-based testing. |
| Regeneration Overhead | Medium | Use Git hooks or CI checks to enforce stub updates. |
| IDE-Specific Quirks | Low | Test with PhpStorm + VSCode for cross-IDE consistency. |
| False Positives in Analysis | Medium | Configure Psalm/PHPStan to ignore stub limitations. |
| Dynamic Class Handling | High | Extend with custom visitors or pre-processing. |
composer.json (e.g., autoload-dev for dev-only stubs).stubs directory in phpstan.neon).composer install.--visitor flag).--include-inaccessible-class-nodes for magic methods.stubs directory to phpstan.neon:
includes:
- stubs/
extension-installer to load stubs dynamically.composer global require php-stubs/generator).// composer.json
"scripts": {
"post-install-cmd": [
"@php-stubs:generate"
],
"php-stubs:generate": "generate-stubs src --out=stubs/ --nullify-globals"
}
--debug flag to inspect generated stubs.File > Invalidate Caches in PhpStorm).phpstan.neon to ignore stub limitations.STUBS.md file explaining:
composer install --no-dev skips stubs).--parallel flag (if supported in future versions).| Failure Mode | Impact | Mitigation |
|---|---|---|
| Stale Stubs | Broken IDE autocompletion | Auto-regenerate in CI/CD. |
| Incorrect Stub Generation | False positives in analysis | Validate with unit tests. |
| IDE Cache Issues | Stub changes not reflected | Clear caches or restart IDE. |
| Static Analysis Conflicts | False errors from stubs | Configure Psalm/PHPStan to ignore stubs. |
| Dynamic Class Mismatches | Missing stubs for Proxies | Use custom visitors or manual stubs. |
How can I help you explore Laravel packages today?