Skip to content

Commit 450cf52

Browse files
authored
Merge branch refs/heads/2.1.x into 2.2.x
2 parents 4512e57 + d9b9af7 commit 450cf52

File tree

8 files changed

+54
-9
lines changed

8 files changed

+54
-9
lines changed

conf/parametersSchema.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ parametersSchema:
126126
?message: string()
127127
?messages: listOf(string())
128128
?rawMessage: string()
129+
?rawMessages: listOf(string())
129130
?identifier: string()
130131
?identifiers: listOf(string())
131132
?path: string()

src/Analyser/Ignore/IgnoredErrorHelper.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function initialize(): IgnoredErrorHelperResult
4040
$expandedIgnoreErrors = [];
4141
foreach ($this->ignoreErrors as $ignoreError) {
4242
if (is_array($ignoreError)) {
43-
if (!isset($ignoreError['message']) && !isset($ignoreError['messages']) && !isset($ignoreError['rawMessage']) && !isset($ignoreError['identifier']) && !isset($ignoreError['identifiers'])) {
43+
if (!isset($ignoreError['message']) && !isset($ignoreError['messages']) && !isset($ignoreError['rawMessage']) && !isset($ignoreError['rawMessages']) && !isset($ignoreError['identifier']) && !isset($ignoreError['identifiers'])) {
4444
$errors[] = sprintf(
4545
'Ignored error %s is missing a message or an identifier.',
4646
Json::encode($ignoreError),
@@ -54,6 +54,13 @@ public function initialize(): IgnoredErrorHelperResult
5454
$expandedIgnoreError['message'] = $message;
5555
$expandedIgnoreErrors[] = $expandedIgnoreError;
5656
}
57+
} elseif (isset($ignoreError['rawMessages'])) {
58+
foreach ($ignoreError['rawMessages'] as $rawMessage) {
59+
$expandedIgnoreError = $ignoreError;
60+
unset($expandedIgnoreError['rawMessages']);
61+
$expandedIgnoreError['rawMessage'] = $rawMessage;
62+
$expandedIgnoreErrors[] = $expandedIgnoreError;
63+
}
5764
} elseif (isset($ignoreError['identifiers'])) {
5865
foreach ($ignoreError['identifiers'] as $identifier) {
5966
$expandedIgnoreError = $ignoreError;

src/DependencyInjection/ContainerFactory.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
use function array_keys;
3838
use function array_map;
3939
use function array_merge;
40+
use function array_slice;
4041
use function array_unique;
4142
use function count;
4243
use function dirname;
@@ -337,20 +338,23 @@ private function validateParameters(array $parameters, array $parametersSchema):
337338
continue;
338339
}
339340

340-
$atLeastOneOf = ['message', 'messages', 'rawMessage', 'identifier', 'identifiers', 'path', 'paths'];
341+
$atLeastOneOf = ['message', 'messages', 'rawMessage', 'rawMessages', 'identifier', 'identifiers', 'path', 'paths'];
341342
if (array_intersect($atLeastOneOf, array_keys($ignoreError)) === []) {
342343
throw new InvalidIgnoredErrorException('An ignoreErrors entry must contain at least one of the following fields: ' . implode(', ', $atLeastOneOf) . '.');
343344
}
344345

345346
foreach ([
346-
['message', 'messages'],
347-
['rawMessage', 'message'],
348-
['rawMessage', 'messages'],
347+
['rawMessage', 'rawMessages', 'message', 'messages'],
349348
['identifier', 'identifiers'],
350349
['path', 'paths'],
351-
] as [$field1, $field2]) {
352-
if (array_key_exists($field1, $ignoreError) && array_key_exists($field2, $ignoreError)) {
353-
throw new InvalidIgnoredErrorException(sprintf('An ignoreErrors entry cannot contain both %s and %s fields.', $field1, $field2));
350+
] as $incompatibleFields) {
351+
foreach ($incompatibleFields as $index => $field1) {
352+
$fieldsToCheck = array_slice($incompatibleFields, $index + 1);
353+
foreach ($fieldsToCheck as $field2) {
354+
if (array_key_exists($field1, $ignoreError) && array_key_exists($field2, $ignoreError)) {
355+
throw new InvalidIgnoredErrorException(sprintf('An ignoreErrors entry cannot contain both %s and %s fields.', $field1, $field2));
356+
}
357+
}
354358
}
355359
}
356360

tests/PHPStan/Analyser/AnalyserTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ public function testFileWithAnIgnoredErrorMessages(): void
136136
$this->assertEquals([], $result);
137137
}
138138

139+
public function testFileWithAnIgnoredErrorRawMessages(): void
140+
{
141+
$result = $this->runAnalyser([['rawMessages' => ['Fail.']]], true, __DIR__ . '/data/bootstrap-error.php', false);
142+
$this->assertEquals([], $result);
143+
}
144+
139145
public function testFileWithAnIgnoredErrorIdentifiers(): void
140146
{
141147
$result = $this->runAnalyser([['identifiers' => ['tests.alwaysFail']]], true, __DIR__ . '/data/bootstrap-error.php', false);

tests/PHPStan/DependencyInjection/InvalidIgnoredErrorExceptionTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ public static function dataValidateIgnoreErrors(): iterable
2727
__DIR__ . '/invalidIgnoreErrors/rawMessage-and-messages.neon',
2828
'An ignoreErrors entry cannot contain both rawMessage and messages fields.',
2929
];
30+
yield [
31+
__DIR__ . '/invalidIgnoreErrors/rawMessage-and-rawMessages.neon',
32+
'An ignoreErrors entry cannot contain both rawMessage and rawMessages fields.',
33+
];
34+
yield [
35+
__DIR__ . '/invalidIgnoreErrors/rawMessages-and-message.neon',
36+
'An ignoreErrors entry cannot contain both rawMessages and message fields.',
37+
];
38+
yield [
39+
__DIR__ . '/invalidIgnoreErrors/rawMessages-and-messages.neon',
40+
'An ignoreErrors entry cannot contain both rawMessages and messages fields.',
41+
];
3042
yield [
3143
__DIR__ . '/invalidIgnoreErrors/identifier-and-identifiers.neon',
3244
'An ignoreErrors entry cannot contain both identifier and identifiers fields.',
@@ -37,7 +49,7 @@ public static function dataValidateIgnoreErrors(): iterable
3749
];
3850
yield [
3951
__DIR__ . '/invalidIgnoreErrors/missing-main-key.neon',
40-
'An ignoreErrors entry must contain at least one of the following fields: message, messages, rawMessage, identifier, identifiers, path, paths.',
52+
'An ignoreErrors entry must contain at least one of the following fields: message, messages, rawMessage, rawMessages, identifier, identifiers, path, paths.',
4153
];
4254
yield [
4355
__DIR__ . '/invalidIgnoreErrors/count-without-path.neon',
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
rawMessage: 'One'
5+
rawMessages: ['Two']
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: '#One#'
5+
rawMessages: ['Two']
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
messages: ['#One#']
5+
rawMessages: ['Two']

0 commit comments

Comments
 (0)