Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions conf/parametersSchema.neon
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ parametersSchema:
?message: string()
?messages: listOf(string())
?rawMessage: string()
?rawMessages: listOf(string())
?identifier: string()
?identifiers: listOf(string())
?path: string()
Expand Down
9 changes: 8 additions & 1 deletion src/Analyser/Ignore/IgnoredErrorHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function initialize(): IgnoredErrorHelperResult
$expandedIgnoreErrors = [];
foreach ($this->ignoreErrors as $ignoreError) {
if (is_array($ignoreError)) {
if (!isset($ignoreError['message']) && !isset($ignoreError['messages']) && !isset($ignoreError['rawMessage']) && !isset($ignoreError['identifier']) && !isset($ignoreError['identifiers'])) {
if (!isset($ignoreError['message']) && !isset($ignoreError['messages']) && !isset($ignoreError['rawMessage']) && !isset($ignoreError['rawMessages']) && !isset($ignoreError['identifier']) && !isset($ignoreError['identifiers'])) {
$errors[] = sprintf(
'Ignored error %s is missing a message or an identifier.',
Json::encode($ignoreError),
Expand All @@ -54,6 +54,13 @@ public function initialize(): IgnoredErrorHelperResult
$expandedIgnoreError['message'] = $message;
$expandedIgnoreErrors[] = $expandedIgnoreError;
}
} elseif (isset($ignoreError['rawMessages'])) {
foreach ($ignoreError['rawMessages'] as $rawMessage) {
$expandedIgnoreError = $ignoreError;
unset($expandedIgnoreError['rawMessages']);
$expandedIgnoreError['rawMessage'] = $rawMessage;
$expandedIgnoreErrors[] = $expandedIgnoreError;
}
} elseif (isset($ignoreError['identifiers'])) {
foreach ($ignoreError['identifiers'] as $identifier) {
$expandedIgnoreError = $ignoreError;
Expand Down
18 changes: 11 additions & 7 deletions src/DependencyInjection/ContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use function array_keys;
use function array_map;
use function array_merge;
use function array_slice;
use function array_unique;
use function count;
use function dirname;
Expand Down Expand Up @@ -337,20 +338,23 @@ private function validateParameters(array $parameters, array $parametersSchema):
continue;
}

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

foreach ([
['message', 'messages'],
['rawMessage', 'message'],
['rawMessage', 'messages'],
['rawMessage', 'rawMessages', 'message', 'messages'],
['identifier', 'identifiers'],
['path', 'paths'],
] as [$field1, $field2]) {
if (array_key_exists($field1, $ignoreError) && array_key_exists($field2, $ignoreError)) {
throw new InvalidIgnoredErrorException(sprintf('An ignoreErrors entry cannot contain both %s and %s fields.', $field1, $field2));
] as $incompatibleFields) {
foreach ($incompatibleFields as $index => $field1) {
$fieldsToCheck = array_slice($incompatibleFields, $index + 1);
foreach ($fieldsToCheck as $field2) {
if (array_key_exists($field1, $ignoreError) && array_key_exists($field2, $ignoreError)) {
throw new InvalidIgnoredErrorException(sprintf('An ignoreErrors entry cannot contain both %s and %s fields.', $field1, $field2));
}
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions tests/PHPStan/Analyser/AnalyserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ public function testFileWithAnIgnoredErrorMessages(): void
$this->assertEquals([], $result);
}

public function testFileWithAnIgnoredErrorRawMessages(): void
{
$result = $this->runAnalyser([['rawMessages' => ['Fail.']]], true, __DIR__ . '/data/bootstrap-error.php', false);
$this->assertEquals([], $result);
}

public function testFileWithAnIgnoredErrorIdentifiers(): void
{
$result = $this->runAnalyser([['identifiers' => ['tests.alwaysFail']]], true, __DIR__ . '/data/bootstrap-error.php', false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ public static function dataValidateIgnoreErrors(): iterable
__DIR__ . '/invalidIgnoreErrors/rawMessage-and-messages.neon',
'An ignoreErrors entry cannot contain both rawMessage and messages fields.',
];
yield [
__DIR__ . '/invalidIgnoreErrors/rawMessage-and-rawMessages.neon',
'An ignoreErrors entry cannot contain both rawMessage and rawMessages fields.',
];
yield [
__DIR__ . '/invalidIgnoreErrors/rawMessages-and-message.neon',
'An ignoreErrors entry cannot contain both rawMessages and message fields.',
];
yield [
__DIR__ . '/invalidIgnoreErrors/rawMessages-and-messages.neon',
'An ignoreErrors entry cannot contain both rawMessages and messages fields.',
];
yield [
__DIR__ . '/invalidIgnoreErrors/identifier-and-identifiers.neon',
'An ignoreErrors entry cannot contain both identifier and identifiers fields.',
Expand All @@ -37,7 +49,7 @@ public static function dataValidateIgnoreErrors(): iterable
];
yield [
__DIR__ . '/invalidIgnoreErrors/missing-main-key.neon',
'An ignoreErrors entry must contain at least one of the following fields: message, messages, rawMessage, identifier, identifiers, path, paths.',
'An ignoreErrors entry must contain at least one of the following fields: message, messages, rawMessage, rawMessages, identifier, identifiers, path, paths.',
];
yield [
__DIR__ . '/invalidIgnoreErrors/count-without-path.neon',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
ignoreErrors:
-
rawMessage: 'One'
rawMessages: ['Two']
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
ignoreErrors:
-
message: '#One#'
rawMessages: ['Two']
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
ignoreErrors:
-
messages: ['#One#']
rawMessages: ['Two']
Loading