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

Generator Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Generate stubs from any PHP code for IDE completion and static analysis.

Frequently asked questions about Generator
How does php-stubs/generator improve Laravel development workflows?
It generates IDE-compatible stubs for untyped or poorly documented PHP code, enabling accurate autocompletion in PhpStorm/VSCode and static analysis with Psalm/PHPStan. This is especially useful for Laravel’s dynamic methods, Facades, or third-party packages lacking PHPDoc.
Can I use this to add type hints to legacy Laravel codebases?
Yes. The generator scans your codebase and creates stubs for dynamic methods (e.g., `__call`, `__get`), Eloquent relationships, or Facades. These stubs can then be used for IDE autocompletion and static analysis without manually adding PHPDoc everywhere.
Does php-stubs/generator work with Laravel’s Facades or Proxies?
It supports Facades and Proxies, but complex cases (like runtime-generated classes) may require custom stub generation flags (e.g., `--visitor`). Test with your IDE to ensure accuracy, as some dynamic class logic might need manual adjustments.
What Laravel versions and PHP versions are supported?
The package works with PHP 8.0+ (Laravel’s minimum version) and is fully compatible with Laravel 8+. It leverages PHP 8’s features like named arguments and union types in generated stubs, but avoid PHP <7.4 unless using PhpParser v4 (deprecated).
How do I integrate this into a Laravel project’s CI/CD pipeline?
Add a GitHub Action or GitLab CI step to regenerate stubs on `composer install` or PRs. Store stubs in `autoload-dev` in `composer.json` and configure Psalm/PHPStan to recognize them. Use pre-commit hooks to warn about stale stubs.
Will generated stubs break static analysis tools like Psalm or PHPStan?
No, but you may need to configure them to recognize stubs. Add a `stubs` directory path in `phpstan.neon` or `psalm.xml` and validate stubs via unit tests. Some dynamic class logic might trigger false positives, which can be ignored in tool configs.
Is there a way to validate stub accuracy before merging to production?
Yes. Run unit tests against stubbed code or use property-based testing to verify behavior. For Laravel, test Facades/Proxies with mocks or integration tests. Automate this in CI to catch stub inaccuracies early.
Can I use this for third-party Laravel packages without modifying their source?
Absolutely. Point the generator at the vendor directory (e.g., `vendor/package-name`) to create stubs for packages lacking PHPDoc. This is ideal for older Laravel add-ons or non-PHP dependencies where you can’t edit the original code.
What’s the best way to handle dynamic class generation (e.g., Eloquent models) with stubs?
For Eloquent or runtime-generated classes, use custom stub visitors or pre-process your code to expose static signatures. The `--visitor` flag helps with complex logic, but test thoroughly—some dynamic behavior may still require manual PHPDoc.
Are there alternatives to php-stubs/generator for Laravel stub generation?
For Laravel-specific needs, consider `vimeo/psalm-plugin-laravel` (for Psalm) or manual PHPDoc. However, php-stubs/generator is more versatile for legacy code, third-party libraries, and dynamic classes. It’s also IDE-agnostic, unlike some toolchain-specific solutions.
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.
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor
spatie/laravel-javascript-views