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

Phan Extensions Laravel Package

drenso/phan-extensions

PhanExtensions provides plugins and stubs for Phan static analysis: Symfony annotation import checking, docblock @method/@throws usage, and inline var comment scanning. Includes stubs for curl, intl, ldap, pdo, radius, and sockets. Not actively maintained.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Static Analysis Tooling: The package extends Phan, a popular static analysis tool for PHP, aligning well with Laravel’s PHP-centric ecosystem. It complements Laravel’s existing tooling (e.g., PHPStan, Psalm) by addressing niche use cases like Symfony annotations, docblock parsing, and stub generation for PHP extensions.
  • Plugin-Based Design: The modular nature of the package (plugins/stubs) allows selective adoption, reducing risk of overhauling existing static analysis pipelines.
  • Laravel-Specific Gaps: While Laravel lacks built-in Phan integration, this package could fill gaps in:
    • Symfony Annotation Handling: Useful for Laravel apps using Symfony components (e.g., Symfony\Component\HttpKernel\Annotation).
    • Docblock Validation: Helps enforce consistency in method/throws annotations, critical for large codebases.
    • PHP Extension Stubbing: Useful for projects using curl, intl, or pdo with custom logic.

Integration Feasibility

  • Low Coupling: Phan operates as a standalone tool, requiring minimal Laravel-specific modifications. Integration would involve:
    1. Adding Phan to composer.json (or CI/CD pipelines).
    2. Configuring Phan with this package’s plugins/stubs.
    3. Hooking Phan into Laravel’s workflow (e.g., Git hooks, CI, or IDE plugins).
  • Compatibility:
    • Phan Version: The package supports Phan ~3.x, which is the latest stable branch (as of 2024). Laravel’s PHP version (8.0+) is compatible.
    • PHP Version: Requires PHP 7.1+, but Laravel’s minimum is 8.0, so no conflicts.
    • Symfony Annotations: Works with Symfony <5.3 (per Phan’s annotation parsing). Laravel’s Symfony components (e.g., HttpKernel) may still use older annotation formats.

Technical Risk

  • Maintenance Risk:
    • Archived Status: The package is unmaintained (last release: 2021). Risks include:
      • Compatibility with newer Phan versions (e.g., Phan 5.x).
      • Bugs in plugins (e.g., ThrowsPlugin is obsolete).
      • Lack of updates for PHP 8.x features (e.g., attributes, named arguments).
    • Mitigation: Fork the repo to maintain compatibility or replace obsolete plugins with community alternatives (e.g., Phan’s built-in @throws support).
  • False Positives/Negatives:
    • Plugins like SymfonyAnnotationPlugin may misclassify annotations, leading to noisy warnings or missed issues.
    • Validation: Test against a subset of Laravel’s codebase (e.g., framework/src) to gauge accuracy.
  • Performance Overhead:
    • Stubbing PHP extensions (e.g., curl) adds analysis time. Benchmark with a large Laravel app (e.g., 50K+ LOC).

Key Questions

  1. Phan Version Compatibility:
    • Does Phan 5.x (latest) break any plugins? If so, can they be patched or replaced?
  2. Laravel-Specific Annotations:
    • Are there Laravel-specific annotations (e.g., Route, Middleware) that could benefit from similar plugins?
  3. CI/CD Integration:
    • How would Phan’s output (e.g., error codes) map to Laravel’s existing linting tools (e.g., php-cs-fixer)?
  4. Alternatives:
    • Would PHPStan’s or Psalm’s built-in features (e.g., annotation parsing) reduce dependency on this package?
  5. Long-Term Strategy:
    • Should this be a temporary fix or a forked/maintained package for Laravel-specific needs?

Integration Approach

Stack Fit

  • Tooling Stack:

    • Phan: Static analysis (type checking, dead code, etc.).
    • Laravel: Framework (PHP 8.0+, Symfony components).
    • CI/CD: GitHub Actions/GitLab CI (for running Phan in pipelines).
    • IDE: PHPStorm/VSCode (for Phan integration via plugins like phan-storm).
  • Overlap with Existing Tools:

    Tool Purpose Conflict Risk
    PHPStan Static analysis High (duplicate effort)
    Psalm Static analysis High
    Pest Testing framework Low
    php-cs-fixer Code style Low

    Recommendation: Use Phan for extension stubbing and annotation parsing, while delegating general type checking to PHPStan/Psalm.

Migration Path

  1. Pilot Phase:
    • Add Phan to a non-critical Laravel module (e.g., a plugin or legacy system).
    • Configure with SymfonyAnnotationPlugin and curl/intl stubs.
    • Validate output against manual reviews.
  2. Gradual Rollout:
    • Integrate Phan into CI/CD (e.g., fail builds on Phan errors).
    • Replace phan-extensions plugins with native Phan/PHPStan features as they mature.
  3. Forking Strategy:
    • If maintenance is critical, fork the repo and:
      • Update for Phan 5.x.
      • Add Laravel-specific annotation support (e.g., Route).
      • Deprecate obsolete plugins (ThrowsPlugin).

Compatibility

  • Phan Configuration: Example phan.config.php for Laravel:
    return [
        'target_php_version' => '8.0',
        'plugins' => [
            'vendor/drenso/phan-extensions/Plugin/Annotation/SymfonyAnnotationPlugin.php',
            'vendor/drenso/phan-extensions/Plugin/DocComment/InlineVarPlugin.php',
        ],
        'stubs' => [
            'vendor/drenso/phan-extensions/Stubs/curl',
            'vendor/drenso/phan-extensions/Stubs/intl',
        ],
        'directory_list' => [
            'app/',
            'config/',
            'database/',
            'routes/',
            'vendor/drenso/phan-extensions/Stubs',
        ],
        'exclude_analysis_directory_list' => [
            'vendor/',
            'vendor/drenso/phan-extensions/Stubs',
        ],
    ];
    
  • CI/CD Example (GitHub Actions):
    name: Phan Static Analysis
    on: [push, pull_request]
    jobs:
      phan:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v4
          - uses: shivammathur/setup-php@v2
            with:
              php-version: '8.0'
          - run: composer require --dev phan/drenso/phan-extensions
          - run: vendor/bin/phan -d app/ --allow-test-incompatible-usage
    
  • IDE Integration:

Sequencing

  1. Phase 1 (Week 1):
    • Set up Phan with basic config (no plugins/stubs).
    • Run against a small codebase to verify no false positives.
  2. Phase 2 (Week 2):
    • Add SymfonyAnnotationPlugin and test with Symfony-heavy modules.
    • Add stubs for used PHP extensions (e.g., intl).
  3. Phase 3 (Week 3):
    • Integrate into CI/CD; fail builds on Phan errors.
    • Compare output with PHPStan/Psalm to avoid redundancy.
  4. Phase 4 (Ongoing):
    • Monitor false positives/negatives.
    • Replace phan-extensions with native solutions where possible.

Operational Impact

Maintenance

  • Pros:
    • Low Maintenance: Phan is a battle-tested tool; the package adds minimal overhead.
    • Selective Use: Plugins/stubs can be enabled/disabled as needed.
  • Cons:
    • Unmaintained Package: Requires vigilance for Phan version updates.
    • Plugin Obsolescence: Some plugins (e.g., ThrowsPlugin) are redundant in newer Phan versions.
  • Mitigation:
    • Schedule quarterly reviews to update Phan and prune unused plugins.
    • Document workarounds for known issues (e.g., Symfony annotations in Laravel 10+).

Support

  • Debugging:
    • Phan provides detailed error messages, but resolving annotation/plugin issues may require:
      • Reviewing Phan’s issue tracker.
      • Checking the forked phan-extensions repo for patches.
    • Laravel-Specific: Support may require custom Phan rules (e.g., for Route annotations).
  • Community:

Scaling

  • Performance:
    • **
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.
terminal42/code-quality-tools
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