Skip to content

✂️ Split PHPStan baseline to multiple files per each error identifier.

Notifications You must be signed in to change notification settings

mll-lab/phpstan-baseline-per-identifier

 
 

Repository files navigation

PHPStan baseline per error identifier

Split your PHPStan baseline into multiple files, one per error identifier:

baselines/
 ├─ loader.neon
 ├─ empty.notAllowed.neon
 ├─ foreach.nonIterable.neon
 ├─ identical.alwaysFalse.neon
 └─ if.condNotBoolean.neon

Each file looks like this:

# total 1 error

parameters:
    ignoreErrors:
        -
            message: '#^Construct empty\(\) is not allowed\. Use more strict comparison\.$#'
            path: ../app/index.php
            count: 1

Installation:

composer require --dev shipmonk/phpstan-baseline-per-identifier

Usage

Important

This usage is available since version 2.0. See legacy usage below if you are still using PHPStan 1.x

Setup baselines loader, other files will be placed beside that file:

# phpstan.neon.dist
includes:
    - baselines/loader.neon # instead of traditional phpstan-baseline.neon

Run native baseline generation and split it into multiple files via our script:

vendor/bin/phpstan --generate-baseline=baselines/loader.neon && vendor/bin/split-phpstan-baseline baselines/loader.neon

(optional) You can simplify generation with e.g. composer script:

{
    "scripts": {
        "generate:baseline:phpstan": [
            "@phpstan --generate-baseline=baselines/loader.neon",
            "@split-phpstan-baseline baselines/loader.neon"
        ]
    }
}

Legacy usage

This usage is deprecated since 2.0, but it works in all versions. Downside is that it cannot utilize result cache

Setup where your baseline files should be stored and include its loader:

# phpstan.neon.dist
includes:
    - vendor/shipmonk/phpstan-baseline-per-identifier/extension.neon # or use extension-installer
    - baselines/loader.neon

parameters:
    shipmonkBaselinePerIdentifier:
        directory: %currentWorkingDirectory%/baselines
        indent: '    '

Prepare composer script to simplify generation:

{
    "scripts": {
        "generate:baseline:phpstan": [
            "rm baselines/*.neon",
            "touch baselines/loader.neon",
            "@phpstan analyse --error-format baselinePerIdentifier"
        ]
    }
}

Cli options

  • --tabs to use tabs as indents in generated neon files

PHP Baseline

  • If the loader file extension is php, the generated files will be php files as well

Migrating from single baseline

  1. rm phpstan-baseline.neon (and remove its include from phpstan.neon.dist)
  2. mkdir baselines
  3. touch baselines/loader.neon (and include it in phpstan.neon.dist)
  4. Run the split script from above

About

✂️ Split PHPStan baseline to multiple files per each error identifier.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%