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

Technical Evaluation

Architecture Fit

  • Use Case Alignment: The 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.
    • Key Laravel Synergies:
      • Legacy Code: Retrofits type hints for dynamic methods (e.g., magic __call, __get) or eloquent relationships.
      • Third-Party Libraries: Adds stubs for vendor packages lacking PHPDoc (e.g., older Laravel add-ons, non-PHP dependencies).
      • Generated Code: Supports Facades, Proxies, and Service Containers by stubbing runtime-generated classes.
    • Limitations:
      • Not a Runtime Tool: Stubs are static-only; critical paths still require formal typing (PHPDoc/return types).
      • Maintenance Dependency: Stubs must be regenerated post-code changes (CI/CD integration required).

Integration Feasibility

  • PHP/Laravel Compatibility:
    • PHP 8.0+: Native support for named arguments, union types, and attributes (Laravel’s minimum version).
    • Composer: Zero-conf integration via composer require php-stubs/generator.
    • PSR-4 Autoloading: Works with Laravel’s class loading but may need custom rules for dynamic classes (e.g., Facades).
  • Toolchain Integration:
    • IDEs: Plugs into PhpStorm (built-in stubs), VSCode (Intelephense), and PHPStorm.
    • Static Analysis: Validates with Psalm/PHPStan (requires config tweaks for stubs).
    • CI/CD: Can be automated (e.g., GitHub Actions) to regenerate stubs on composer install or PRs.
  • Laravel-Specific Challenges:
    • Dynamic Class Loading: Laravel’s Facades, Proxies, and Eloquent may need custom stub generation (e.g., --visitor flag for complex logic).
    • Framework Internals: Core Laravel classes (e.g., Illuminate\Support\Facades\Facade) are already stubbed, but custom packages may require manual tuning.

Technical Risk

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.

Key Questions for TPM

  1. Primary Goal: Is this for legacy code, third-party libraries, or developer onboarding?
  2. Maintenance Strategy: Will stubs be version-controlled or auto-generated in CI?
  3. Tooling Stack: Which static analyzers (Psalm/PHPStan) and IDEs are in use?
  4. Dynamic Classes: Are there Facades, Proxies, or runtime-generated classes needing special handling?
  5. CI/CD Integration: How will stubs be validated/regenerated in pipelines?

Integration Approach

Stack Fit

  • Core Stack: Fully compatible with Laravel + PHP 8.0+, Composer, and PSR-4 autoloading.
  • Tooling Compatibility:
    • IDEs: Native support in PhpStorm, VSCode (Intelephense), and PHPStorm.
    • Static Analysis: Works with Psalm, PHPStan, and PHPMD (requires config adjustments).
    • Testing: Can integrate with PHPUnit for stub validation.
  • Non-Fit Considerations:
    • JIT Compilation (OPcache): No runtime impact, but stubs must be pre-generated.
    • Legacy PHP (<7.4): Requires PhpParser v4 (deprecated; avoid unless necessary).

Migration Path

  1. Pilot Phase:
    • Generate stubs for one legacy module or third-party library.
    • Validate with IDE autocompletion and static analysis.
  2. Toolchain Integration:
    • Add stubs to composer.json (e.g., autoload-dev for dev-only stubs).
    • Configure Psalm/PHPStan to recognize stubs (e.g., stubs directory in phpstan.neon).
  3. CI/CD Automation:
    • Use GitHub Actions/GitLab CI to regenerate stubs on composer install.
    • Add pre-commit hooks to warn about stale stubs.
  4. Full Rollout:
    • Expand to all PHP modules (prioritize high-impact areas).
    • Document stub generation in developer onboarding.

Compatibility

  • Laravel-Specific:
    • Facades/Proxies: May need custom stub generation (e.g., --visitor flag).
    • Dynamic Methods: Use --include-inaccessible-class-nodes for magic methods.
  • Third-Party Libraries:
    • Works out-of-the-box for PSR-4 autoloaded code.
    • May require manual PHPDoc tweaks for complex logic.
  • Static Analysis:
    • Psalm: Add stubs directory to phpstan.neon:
      includes:
        - stubs/
      
    • PHPStan: Use extension-installer to load stubs dynamically.

Sequencing

  1. Phase 1 (0-2 weeks):
    • Install package globally (composer global require php-stubs/generator).
    • Generate stubs for a single module and validate.
  2. Phase 2 (2-4 weeks):
    • Integrate with CI/CD (auto-regenerate stubs).
    • Configure Psalm/PHPStan to use stubs.
  3. Phase 3 (4+ weeks):
    • Roll out to all PHP modules.
    • Document stub generation in developer guides.

Operational Impact

Maintenance

  • Regeneration Workflow:
    • Stubs must be regenerated when source code changes.
    • Automate via Composer scripts or CI hooks:
      // composer.json
      "scripts": {
        "post-install-cmd": [
          "@php-stubs:generate"
        ],
        "php-stubs:generate": "generate-stubs src --out=stubs/ --nullify-globals"
      }
      
  • Version Control:
    • Option 1: Commit stubs to Git (for reproducibility).
    • Option 2: Regenerate dynamically (CI-only, reduces merge conflicts).

Support

  • Troubleshooting:
    • Stub Accuracy Issues: Use --debug flag to inspect generated stubs.
    • IDE Misbehavior: Clear IDE caches (File > Invalidate Caches in PhpStorm).
    • Static Analysis Errors: Adjust phpstan.neon to ignore stub limitations.
  • Documentation:
    • Add a STUBS.md file explaining:
      • How to regenerate stubs.
      • Known limitations (e.g., dynamic classes).
      • IDE/static analysis configurations.

Scaling

  • Performance:
    • Generation Time: Linear with codebase size (test on largest module first).
    • CI Impact: Minimal if cached (e.g., composer install --no-dev skips stubs).
  • Large Codebases:
    • Parallelize: Use --parallel flag (if supported in future versions).
    • Incremental Updates: Regenerate only changed directories.

Failure Modes

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.

Ramp-Up

  • **
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.
codifyo/ts-generator-bundle
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