Skip to content

PHPStan error formatter that generates baseline files per each error identifier.

Notifications You must be signed in to change notification settings

shipmonk-rnd/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

Use official extension-installer or just load the extension:

includes:
    - vendor/shipmonk/phpstan-baseline-per-identifier/extension.neon

Usage:

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

# phpstan.neon.dist
includes:
    - 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"
        ]
    }
}

Regenerate the baselines:

composer generate:baseline:phpstan

Migration from single baseline

  1. rm phpstan-baseline.neon (and remove its include from phpstan.neon.dist)
  2. mkdir baselines
  3. composer generate:baseline:phpstan

About

PHPStan error formatter that generates baseline files per each error identifier.

Topics

Resources

Stars

Watchers

Forks

Languages