Skip to content

PHPStan task incompatible with baseline functionality - hangs when processing individual files #113

@tormi

Description

@tormi

Problem Description

The Wunderio PHPStan task (Wunderio\GrumPHP\Task\PhpStan\PhpStanTask) is incompatible with PHPStan's baseline functionality, causing the task to hang or fail during execution.

Technical Details

Root Cause:
The Wunderio PHPStan task extends AbstractMultiPathProcessingTask and processes files individually by adding each file as a separate argument to the PHPStan command:

// From PhpStanTask.php lines 34-36
foreach ($files as $file) {
  $arguments->add($file);
}

Why This Breaks Baselines:

  • PHPStan baselines require the tool to analyze all configured paths together as a cohesive project
  • Individual file analysis prevents PHPStan from understanding the full context needed for baseline matching
  • The baseline file contains project-wide error patterns that only make sense when analyzing the complete codebase

Observed Behavior:

  • PHPStan task hangs indefinitely when baseline is configured
  • No error output or completion status
  • Other GrumPHP tasks complete successfully

Current Workaround

Users must:

  1. Remove the Wunderio PHPStan extension from grumphp.yml:

    extensions:
      # - Wunderio\GrumPHP\Task\PhpStan\PhpStanExtensionLoader  # Remove this
  2. Use the standard GrumPHP PHPStan task instead:

    tasks:
      phpstan:  # Note: 'phpstan' not 'php_stan'
        configuration: phpstan.neon
        memory_limit: "1G"
        use_grumphp_paths: false  # Let PHPStan use its own path config

Suggested Solutions

Option 1: Configuration Flag

Add a configuration option to the Wunderio PHPStan task:

tasks:
  php_stan:
    use_individual_files: false  # Default: true for backward compatibility
    configuration: phpstan.neon

When use_individual_files: false, the task should rely on PHPStan's configuration file for paths instead of processing individual files.

Option 2: Documentation

Provide clear guidance on when to use:

  • Wunderio PHPStan task: For file-by-file analysis without baselines
  • Standard GrumPHP PHPStan task: For project-wide analysis with baseline support

Option 3: Auto-detection

Detect if a baseline file is configured and automatically switch to project-wide analysis mode.

Impact

This issue affects:

  • Projects implementing PHPStan level 9 with baseline files for gradual code quality improvement
  • Teams wanting to establish quality gates while managing technical debt
  • CI/CD pipelines that hang due to the PHPStan task not completing

Environment

  • wunderio/code-quality: Latest version
  • PHPStan: Level 9 with baseline file
  • GrumPHP: Via wunderio/code-quality
  • Use case: Drupal projects with custom modules

Example Configuration That Fails

# grumphp.yml
tasks:
  php_stan:
    configuration: phpstan.neon
    memory_limit: "1G"
extensions:
  - Wunderio\GrumPHP\Task\PhpStan\PhpStanExtensionLoader
# phpstan.neon
includes:
  - phpstan-baseline.neon
parameters:
  level: 9
  paths:
    - web/modules/custom

This configuration causes the PHPStan task to hang indefinitely.


Would appreciate guidance on the preferred approach for resolving this incompatibility. Happy to contribute a PR once the direction is clarified!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions