Skip to content

Commit d067441

Browse files
authored
Fix fatal error when path has array value in ignoreErrors (#5183)
1 parent 873f1e6 commit d067441

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

src/DependencyInjection/ValidateIgnoredErrorsExtension.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@
3838
use function array_keys;
3939
use function array_map;
4040
use function count;
41+
use function gettype;
4142
use function implode;
4243
use function is_array;
4344
use function is_dir;
4445
use function is_file;
46+
use function is_string;
4547
use function sprintf;
4648
use const PHP_VERSION_ID;
4749

@@ -167,8 +169,16 @@ public function getRegistry(): OperatorTypeSpecifyingExtensionRegistry
167169
}
168170

169171
if (isset($ignoreError['path'])) {
172+
if (!is_string($ignoreError['path'])) {
173+
$errors[] = sprintf("Key 'path' of ignoreErrors expects a string, %s given. Did you mean 'paths'?", gettype($ignoreError['path']));
174+
continue;
175+
}
170176
$ignorePaths = [$ignoreError['path']];
171177
} elseif (isset($ignoreError['paths'])) {
178+
if (!is_array($ignoreError['paths'])) {
179+
$errors[] = sprintf("Key 'paths' of ignoreErrors expects an array, %s given. Did you mean 'path'?", gettype($ignoreError['paths']));
180+
continue;
181+
}
172182
$ignorePaths = $ignoreError['paths'];
173183
} else {
174184
continue;

tests/PHPStan/DependencyInjection/InvalidIgnoredErrorExceptionTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ public static function dataValidateIgnoreErrors(): iterable
5555
__DIR__ . '/invalidIgnoreErrors/count-without-path.neon',
5656
'An ignoreErrors entry with count field must also contain path field.',
5757
];
58+
yield [
59+
__DIR__ . '/invalidIgnoreErrors/path-with-array-value.neon',
60+
"Key 'path' of ignoreErrors expects a string, array given. Did you mean 'paths'?",
61+
];
62+
yield [
63+
__DIR__ . '/invalidIgnoreErrors/paths-with-string-value.neon',
64+
"Key 'paths' of ignoreErrors expects an array, string given. Did you mean 'path'?",
65+
];
5866
}
5967

6068
#[DataProvider('dataValidateIgnoreErrors')]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
identifier: some.identifier
5+
path:
6+
- tests/some-file.php
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
identifier: some.identifier
5+
paths: tests/some-file.php

0 commit comments

Comments
 (0)