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

Phpstan Baseline Per Identifier Laravel Package

shipmonk/phpstan-baseline-per-identifier

Split a PHPStan baseline into multiple NEON files grouped by error identifier, with a loader include. Generate baseline as usual, then run split-phpstan-baseline to organize ignores per identifier for easier reviews and maintenance.

View on GitHub
Deep Wiki
Context7

Getting Started

Start by installing the package and configuring the new baseline structure. First, run:

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

Then remove your existing single baseline include from phpstan.neon.dist (e.g., includes: - phpstan-baseline.neon), and set up the loader-based workflow:

  1. Generate a temporary single-file baseline with --generate-baseline=baselines/_loader.neon
  2. Run vendor/bin/split-phpstan-baseline baselines/_loader.neon to split it
  3. Ensure includes: - baselines/_loader.neon is in your PHPStan config

This instantly enables per-error baseline files (e.g., baselines/empty.notAllowed.neon) for easier review and management.

Implementation Patterns

  • Use Composer scripts for automation
    Define scripts like:

    {
        "scripts": {
            "phpstan:baseline": [
                "phpstan --generate-baseline=baselines/_loader.neon",
                "split-phpstan-baseline baselines/_loader.neon"
            ],
            "phpstan:baseline:update": [
                "phpstan analyse --error-format=raw",
                "@phpstan:baseline"
            ]
        }
    }
    

    This makes baseline regeneration part of CI/CD and PR workflows.

  • Leverage PHP baselines for consistency
    If your project already uses baseline.php, switch to baselines/loader.php — the same splitting logic applies, and it integrates with PHPStan’s result cache.

  • Integrate with CI
    In CI, run phpstan analyse without regeneration, then fail only on new errors (since baselines are pre-split and versioned). Use --error-format=raw for human-readable logs.

  • Team workflow
    Developers can inspect/modify specific error types (e.g., foreach.nonIterable.neon) in small diffs, reducing merge conflicts and improving review focus.

Gotchas and Tips

  • Cache invalidation pitfall
    PHP baselines require .php extension for cache to work correctly — don’t accidentally name it _loader.neon if you want PHP output. Double-check the loader file extension determines the generated file format.

  • Preserved error order = cleaner diffs (v2.3+)
    Since 2.3.0, regenerating baselines preserves the original order of existing errors and only inserts new ones at sorted positions — no need for manual sorting or sort scripts. Rely on this for predictable diffs.

  • Orphaned file cleanup
    The split-phpstan-baseline command auto-deletes baseline files that no longer have errors — remove any old find baselines -name "*.neon" -delete scripts.

  • CLI options for cleaner baselines
    Use --no-error-count if your team prefers uncluttered files (e.g., for compliance), or --tabs for consistency with your repo’s formatting.

  • Legacy vs modern workflow
    If you see --error-format baselinePerIdentifier in old scripts, replace it with --generate-baseline + split-phpstan-baseline. The legacy method cannot use result cache and lacks rawMessage support.

  • Check loader includes total count (v2.1.5+)
    The loader file now includes the total error count in its header comment — useful for verifying completeness after splits.

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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4
php-http/client-implementation
phpcr/phpcr-implementation
cucumber/gherkin-monorepo
haydenpierce/class-finder
psr/simple-cache-implementation
uri-template/tests