Skip to content

Commit bf04c05

Browse files
VincentLangletphpstan-bot
authored andcommitted
Fix phpstan/phpstan#12430: Skip path validation for baseline entries
- 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
1 parent 06ea1e1 commit bf04c05

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

src/DependencyInjection/ValidateIgnoredErrorsExtension.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ public function getRegistry(): UnaryOperatorTypeSpecifyingExtensionRegistry
177177
continue;
178178
}
179179

180+
if (isset($ignoreError['count'])) {
181+
continue; // ignoreError coming from baseline will be validated at runtime
182+
}
183+
180184
if (isset($ignoreError['path'])) {
181185
if (!is_string($ignoreError['path'])) {
182186
$errors[] = sprintf("Key 'path' of ignoreErrors expects a string, %s given. Did you mean 'paths'?", gettype($ignoreError['path']));

tests/PHPStan/DependencyInjection/InvalidIgnoredErrorExceptionTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ public function testValidateIgnoreErrors(string $file, string $expectedMessage):
7373
self::getContainer();
7474
}
7575

76+
public function testBug12430(): void
77+
{
78+
self::$configFile = __DIR__ . '/invalidIgnoreErrors/baseline-nonexistent-path.neon';
79+
$this->expectNotToPerformAssertions();
80+
self::getContainer();
81+
}
82+
7683
public static function getAdditionalConfigFiles(): array
7784
{
7885
$files = [
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: '#Some error#'
5+
count: 1
6+
path: /nonexistent/path/to/deleted/file.php

0 commit comments

Comments
 (0)