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

Infection Static Analysis Plugin Laravel Package

roave/infection-static-analysis-plugin

Adds a wrapper around infection/infection that runs Psalm on generated mutants. Mutations that would cause type errors are marked killed, improving mutation score. Run vendor/bin/roave-infection-static-analysis-plugin; supports Infection args plus --psalm-config.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Mutation Testing + Static Analysis Synergy: The plugin integrates seamlessly with Infection (mutation testing) and Psalm (static analysis), addressing a critical gap in PHP testing ecosystems. It leverages mutation testing to identify code vulnerabilities while using static analysis to filter out invalid mutants (e.g., type violations), improving mutation score accuracy.
  • Laravel Compatibility: Laravel’s reliance on PHPUnit and static analysis tools (e.g., Psalm, PHPStan) makes this plugin a natural fit. Laravel’s type-hinted codebase (e.g., in Laravel 8+) benefits from stricter type enforcement, reducing false positives in mutation tests.
  • Plugin-Based Design: The plugin replaces infection’s CLI binary, requiring minimal architectural changes. It hooks into Infection’s workflow without modifying core Laravel components, adhering to dependency inversion principles.

Integration Feasibility

  • Low-Coupling Integration: The plugin operates at the toolchain level (CI/CD, local dev), not the framework level. No Laravel-specific modifications are needed beyond:
    • Installing the plugin (composer require --dev roave/infection-static-analysis-plugin).
    • Replacing vendor/bin/infection with vendor/bin/roave-infection-static-analysis-plugin.
  • Static Analysis Tool Agnosticism: While Psalm is the primary focus, the plugin’s design suggests future support for PHPStan or other tools, aligning with Laravel’s multi-tool ecosystem (e.g., Pest, PestPlugin).
  • CI/CD Pipeline Fit: Ideal for GitHub Actions, GitLab CI, or CircleCI pipelines where mutation testing is already implemented. Can be gated as a pre-merge check or nightly job.

Technical Risk

  • Version Pinning Risk: The plugin pins to specific Infection versions (e.g., infection/infection:0.32.0), risking breakage if Laravel’s dev dependencies update. Mitigation:
    • Lock versions in composer.json (e.g., infection/infection:^0.32.0).
    • Monitor Roave’s release notes for compatibility updates.
  • Performance Overhead: Static analysis adds ~2–5x slower execution than Infection alone. Risk in:
    • Large codebases (e.g., Laravel + Forge/Sail plugins).
    • CI timeouts (e.g., GitHub Actions’ 6-hour limit).
    • Mitigation: Run in parallel (if supported) or incrementally (e.g., target specific directories).
  • False Positives/Negatives:
    • Static analysis may incorrectly flag valid mutants (e.g., dynamic type handling in Laravel’s Container).
    • Mitigation: Tune Psalm config (e.g., @psalm-suppress annotations) or exclude problematic paths.
  • Toolchain Fragmentation: Requires Psalm/PHPStan to be pre-configured. Risk in teams not using static analysis.
    • Mitigation: Treat as a phased adoption (start with Infection, add plugin later).

Key Questions

  1. Static Analysis Tool Preference:
    • Does the team use Psalm, PHPStan, or another tool? The plugin currently supports only Psalm.
  2. CI/CD Constraints:
    • Can the pipeline accommodate the performance overhead? If not, consider partial runs (e.g., --only-tests flag).
  3. Version Compatibility:
    • What versions of Infection, PHPUnit, and Psalm are used in Laravel’s dev stack? Ensure alignment with the plugin’s pinned versions.
  4. False Positive Tolerance:
    • How will the team handle static analysis conflicts (e.g., Laravel’s dynamic method calls)? Will annotations or exclusions be needed?
  5. Long-Term Maintenance:
    • Is the team willing to monitor Roave’s updates for Infection compatibility? Alternatively, can a custom fork be maintained?

Integration Approach

Stack Fit

  • Laravel Ecosystem Alignment:
    • PHPUnit: The plugin inherits Infection’s PHPUnit integration, making it compatible with Laravel’s default testing stack.
    • Psalm/PHPStan: Laravel’s growing adoption of static analysis (e.g., via spatie/laravel-psalm) makes this plugin a natural extension.
    • Dev Containers/Forge: The plugin’s CLI-based nature fits well with Laravel’s Sail or Laravel Valet environments.
  • Toolchain Compatibility:
    • Works with Pest (via PHPUnit compatibility) and Laravel’s testing helpers (e.g., RefreshDatabase).
    • Integrates with Laravel Forge/Envoyer for deployment-level mutation testing.

Migration Path

  1. Phase 1: Baseline Mutation Testing
    • Install and configure Infection (composer require --dev infection/infection).
    • Run baseline tests: ./vendor/bin/infection.
    • Document current mutation score and escaped mutants.
  2. Phase 2: Plugin Integration
    • Install the plugin: composer require --dev roave/infection-static-analysis-plugin.
    • Replace Infection’s binary: Update scripts (e.g., phpunit.xml, CI configs) to use roave-infection-static-analysis-plugin.
    • Configure Psalm: Add --psalm-config=config/psalm.xml to CLI args.
  3. Phase 3: Validation
    • Compare mutation scores before/after plugin adoption.
    • Audit false positives/negatives and adjust Psalm config or test coverage.
  4. Phase 4: CI/CD Integration
    • Add the plugin to pre-merge checks (e.g., GitHub Actions).
    • Set minimum mutation score thresholds (e.g., >90%).

Compatibility

Component Compatibility Mitigation
Laravel Version All (8.0+) Test with target Laravel version.
PHP Version 8.1–8.5 (plugin supports 8.5; Laravel drops 8.1 in 11.x) Pin PHP version in CI.
Infection Version Pinned to 0.32.0 (check latest plugin release for updates) Lock version in composer.json.
Psalm/PHPStan Psalm required (PHPStan planned for future) Ensure Psalm is configured.
CI/CD Systems GitHub Actions, GitLab CI, CircleCI (any CLI-compatible system) Adjust timeout limits if needed.
Custom Laravel Code May trigger false positives (e.g., dynamic method calls) Use @psalm-suppress or exclude paths.

Sequencing

  1. Pre-Requisite: Ensure Infection is already part of the workflow (avoid introducing two new tools at once).
  2. Order of Operations:
    • Install plugin after Infection (to avoid version conflicts).
    • Configure Psalm first, then integrate the plugin.
  3. Rollback Plan:
    • If performance is unacceptable, revert to infection/infection by removing the plugin and updating scripts.
    • Use composer remove roave/infection-static-analysis-plugin to revert.

Operational Impact

Maintenance

  • Dependency Management:
    • High: The plugin pins Infection and Psalm versions, requiring manual updates when Roave releases compatibility patches.
    • Action: Schedule quarterly dependency reviews to align with Laravel’s update cycles.
  • Configuration Drift:
    • Medium: Psalm config (psalm.xml) may need adjustments as Laravel’s codebase evolves (e.g., new type-hinted methods).
    • Action: Document Psalm rules in the team’s testing guidelines.
  • Plugin Updates:
    • Low-Medium: Minor updates (e.g., PHP 8.5 support) are handled via composer update. Major updates may require testing.
    • Action: Test plugin updates in a staging environment before production.

Support

  • Debugging Complexity:
    • High: Issues may stem from:
      • Infection internals (plugin’s "hacky" bootstrap).
      • Psalm misconfigurations (e.g., incorrect type expectations in Laravel’s Container).
    • Action:
      • Maintain a troubleshooting guide with common Psalm/Laravel conflicts.
      • Use --verbose flags for detailed logs.
  • Community Resources:
    • Medium: Limited direct support (Roave’s plugin is niche). Rely on:
      • Infection’s GitHub issues (for plugin-related bugs).
      • Psalm’s documentation (for static analysis problems).
    • Action: Engage with Laravel’s Slack/Discord for community-driven solutions.

Scaling

  • Performance Bottlenecks:
    • High: Static analysis adds O(n²) complexity for large codebases (e.g., Laravel +
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