Skip to content

Fix phpstan/phpstan#12430: Baseline generator won't take care of removing errors from changed file locations or renames#5414

Closed
phpstan-bot wants to merge 1 commit intophpstan:2.1.xfrom
phpstan-bot:create-pull-request/patch-fyt7u81
Closed

Fix phpstan/phpstan#12430: Baseline generator won't take care of removing errors from changed file locations or renames#5414
phpstan-bot wants to merge 1 commit intophpstan:2.1.xfrom
phpstan-bot:create-pull-request/patch-fyt7u81

Conversation

@phpstan-bot
Copy link
Copy Markdown
Collaborator

Summary

When files are deleted or renamed, their baseline entries contain paths that no longer exist. PHPStan refused to run with "Path ... is neither a directory, nor a file path, nor a fnmatch pattern" instead of treating them as unmatched ignored errors at runtime.

Changes

  • Added count key check to skip baseline entries during path validation in src/DependencyInjection/ValidateIgnoredErrorsExtension.php
  • Added regression test in tests/PHPStan/DependencyInjection/InvalidIgnoredErrorExceptionTest.php
  • Added test fixture tests/PHPStan/DependencyInjection/invalidIgnoreErrors/baseline-nonexistent-path.neon

Root cause

In ValidateIgnoredErrorsExtension::loadConfiguration(), the message validation loop (line 148) already skipped baseline entries (those with a count key) with the comment "ignoreError coming from baseline will be correct". However, the path validation loop (line 174) did not have this same check, so baseline entries with paths to deleted/renamed files triggered the hard error during container initialization instead of being handled gracefully at runtime as unmatched ignored errors.

Test

The regression test loads a config with a baseline-style ignoreErrors entry (with count and a non-existent path) and verifies that the container can be created without throwing InvalidIgnoredErrorPatternsException.

Fixes phpstan/phpstan#12430

- Baseline entries (identified by having a 'count' key) with paths to
  deleted/renamed files caused "is neither a directory, nor a file path,
  nor a fnmatch pattern" errors during container initialization
- The message validation already skipped baseline entries but the path
  validation did not
- Added the same 'count' check to skip baseline entries in the path
  validation loop in ValidateIgnoredErrorsExtension
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants