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

Phpstan Extension Ide Helper Laravel Package

headercat/phpstan-extension-ide-helper

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation:

    composer require --dev headercat/phpstan-extension-ide-helper:^2.2.4
    

    Ensure phpstan/phpstan:^2.2.0 is installed in require-dev (required for compatibility).

  2. Trigger IDE Helper Generation: Run the helper to generate stubs for PHPStan 2.2.4:

    vendor/bin/phpstan-extension-ide-helper generate
    

    Stubs are generated in ./stubs/phpstan/ (default) with updated 2.2.4 API coverage.

  3. Configure IDE:

    • PHPStorm: Add stubs/phpstan/ to "PHPStan" settings under Settings > Languages & Frameworks > PHP > PHPStan.
    • VSCode: Ensure the PHPStan extension uses the generated stubs (verify phpstan.phar path and stub directory).
  4. First Use Case: Write a PHPStan extension (e.g., a custom rule). Leverage autocompletion for:

    • New 2.2.4 classes like PhpStan\Analyser\Error or PhpStan\Rules\Type\TypeRule.
    • Updated methods in PhpStan\Rule\Rule (e.g., refineNodes() with new parameters).
    • Reflection APIs like PhpStan\Reflection\MethodReflection::getReturnType().

Implementation Patterns

Workflows

  1. Extension Development with 2.2.4:

    • Rule Creation: Extend PhpStan\Rule\Rule with autocompletion for new abstract methods like getNodeType() or refineNodes().
      use PhpStan\Rules\Type\TypeRule; // New in 2.2.4
      
      class CustomTypeRule extends TypeRule {
          public function getNodeType(): string {
              return TypeRule::BUILTIN_TYPE_STRING;
          }
      }
      
    • Error Handling: Use PhpStan\Analyser\Error stubs for reporting issues:
      $this->reportError($error, $node); // Autocompleted
      
    • Reflection: Access updated reflection APIs (e.g., PhpStan\Reflection\ClassReflection::getNativeMethods()).
  2. Integration with PHPStan 2.2.4:

    • Place extensions in src/Rules/ or src/Extension/ and reference stubs for:
      • New PhpStan\Broker\Container methods (e.g., getRuleLoader()).
      • Updated PhpStan\Analyser\Scope APIs (e.g., getFunction() with new parameters).
    • Example:
      use PhpStan\Broker\Container; // Autocompleted
      use PhpStan\Analyser\Error;   // Autocompleted
      
      class MyExtension implements Extension {
          public function getRuleLoader(): RuleLoader {
              return RuleLoader::createFromRulesetProvider($this);
          }
      }
      
  3. Testing with 2.2.4:

    • Use stubs to mock updated internals (e.g., PhpStan\Testing\PhpStanTestCase with new assertions):
      use PhpStan\Testing\PhpStanTestCase;
      use PhpStan\Analyser\Error; // Autocompleted
      
      class CustomRuleTest extends PhpStanTestCase {
          public function testErrorReporting() {
              $this->analyse([__DIR__ . '/fixtures/test.php']);
              $this->assertErrorLogged(Error::LEVEL_ERROR, 'Custom error message');
          }
      }
      

Tips for Smooth Integration

  • Stub Location: Override the output path for 2.2.4-specific stubs:
    vendor/bin/phpstan-extension-ide-helper generate --output=./stubs/phpstan-2.2.4/
    
  • Composer Autoload: Update composer.json to include the new stubs:
    "autoload-dev": {
        "psr-4": {
            "PhpStan\\": ["./stubs/phpstan/", "./stubs/phpstan-2.2.4/"]
        }
    }
    
  • CI/CD: Regenerate stubs in CI for 2.2.4 compatibility:
    - name: Generate PHPStan 2.2.4 stubs
      run: composer require phpstan/phpstan:^2.2.0 && vendor/bin/phpstan-extension-ide-helper generate
    

Gotchas and Tips

Pitfalls

  1. Stub Version Mismatch (Critical):

    • Issue: Stubs generated for PHPStan <2.2.0 will break with 2.2.4 due to:
      • New abstract methods in PhpStan\Rule\Rule.
      • Removed or renamed classes (e.g., PhpStan\Rules\Functions\* restructuring).
    • Fix: Always regenerate stubs after updating PHPStan:
      composer require phpstan/phpstan:^2.2.0
      vendor/bin/phpstan-extension-ide-helper generate --force
      
  2. IDE-Specific Quirks (Updated):

    • PHPStorm: Clear caches (File > Invalidate Caches) if autocompletion fails after stub generation.
      • Verify phpstan.phar points to ./vendor/bin/phpstan.phar in Settings > PHPStan.
    • VSCode: Ensure the PHPStan extension uses the correct stub path (check phpstan.stubsPath in settings).
  3. Missing 2.2.4 Namespaces:

    • Issue: Some new namespaces (e.g., PhpStan\Type\ObjectType) may lack stubs.
    • Workaround:
      • Manually add stubs by copying from phpstan-src.
      • Report missing namespaces to the issue tracker.
  4. Dependency Conflicts:

    • Issue: Conflicts may arise if phpstan/phpstan-src isn’t cloned during stub generation.
    • Fix: Ensure the helper has access to the phpstan-src repo (check composer.json for headercat/phpstan-extension-ide-helper dependencies).

Debugging

  • Verify Stubs: Check ./stubs/phpstan/PhpStan/ for new files like:
    PhpStan/
    ├── Analyser/
    │   ├── Error.php          # New in 2.2.4
    ├── Rules/
    │   ├── Type/              # Restructured
    │   │   ├── TypeRule.php
    ├── Reflection/
    │   ├── MethodReflection.php
    
  • Log Generation: Enable verbose output for 2.2.4-specific issues:
    vendor/bin/phpstan-extension-ide-helper generate --verbose
    
  • Manual Validation: Test autocompletion for critical 2.2.4 classes:
    • PhpStan\Analyser\Error::LEVEL_ERROR
    • PhpStan\Rules\Type\TypeRule::getNodeType()

Extension Points

  1. Custom Stub Generation for 2.2.4:

    • Fork the helper to add support for new PHPStan 2.2.4 features (e.g., PhpStan\Type\ObjectType).
    • Modify src/Generator.php to include additional paths from phpstan-src (check phpstan-src/PhpStan/).
  2. IDE-Specific Enhancements:

    • Add PHPDoc tags to stubs for 2.2.4-specific methods (e.g., @method static Error create(string $message)).
    • Example:
      // In a generated stub file
      namespace PhpStan\Analyser;
      
      /**
       * @method static Error create(string $message, int $level = Error::LEVEL_ERROR)
       */
      class Error {}
      
  3. CI Automation for 2.2.4:

    • Extend workflows to auto-generate and commit stubs:
      - name: Generate and commit PHPStan 2.2.4 stubs
        run: |
          composer require phpstan/phpstan:^2.2.0
          vendor/bin/phpstan-extension-ide-helper generate
          git add stubs/phpstan/
          git commit -m "chore: update PHPStan 2.2.4 stubs"
      
    • Cache stubs between runs to avoid regeneration:
      - name: Cache PHPStan stubs
        uses: actions/cache@v3
        with:
          path: stubs/phpstan/
          key: phpstan-stubs-2.2.4
      
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.
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
ecotone/kafka
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata