Skip to content

Commit 5c9e084

Browse files
committed
Use "Ignored error" instead of "Ignored error pattern" when rawMessage is used
1 parent 4557edd commit 5c9e084

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

src/Analyser/Ignore/IgnoredError.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@
1717
final class IgnoredError
1818
{
1919

20+
/**
21+
* @param array{message?: string, rawMessage?: string, identifier?: string, identifiers?: list<string>, path?: string, paths?: list<string>}|string $ignoredError
22+
*/
23+
public static function getIgnoredErrorLabel(array|string $ignoredError): string
24+
{
25+
if (is_array($ignoredError) && !isset($ignoredError['message']) && isset($ignoredError['rawMessage'])) {
26+
return 'Ignored error';
27+
}
28+
29+
return 'Ignored error pattern';
30+
}
31+
2032
/**
2133
* @param mixed[]|string $ignoredError
2234
* @return string Representation of the ignored error

src/Analyser/Ignore/IgnoredErrorHelperResult.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ public function process(
181181
}
182182

183183
$errors[] = (new Error(sprintf(
184-
'Ignored error pattern %s is expected to occur %d %s, but occurred %d %s.',
184+
'%s %s is expected to occur %d %s, but occurred %d %s.',
185+
IgnoredError::getIgnoredErrorLabel($unmatchedIgnoredError),
185186
IgnoredError::stringifyPattern($unmatchedIgnoredError),
186187
$unmatchedIgnoredError['count'],
187188
$unmatchedIgnoredError['count'] === 1 ? 'time' : 'times',
@@ -205,7 +206,8 @@ public function process(
205206
) {
206207
if ($unmatchedIgnoredError['realCount'] < $unmatchedIgnoredError['count']) {
207208
$errors[] = (new Error(sprintf(
208-
'Ignored error pattern %s is expected to occur %d %s, but occurred only %d %s.',
209+
'%s %s is expected to occur %d %s, but occurred only %d %s.',
210+
IgnoredError::getIgnoredErrorLabel($unmatchedIgnoredError),
209211
IgnoredError::stringifyPattern($unmatchedIgnoredError),
210212
$unmatchedIgnoredError['count'],
211213
$unmatchedIgnoredError['count'] === 1 ? 'time' : 'times',
@@ -224,15 +226,17 @@ public function process(
224226

225227
$errors[] = (new Error(
226228
sprintf(
227-
'Ignored error pattern %s was not matched in reported errors.',
229+
'%s %s was not matched in reported errors.',
230+
IgnoredError::getIgnoredErrorLabel($unmatchedIgnoredError),
228231
IgnoredError::stringifyPattern($unmatchedIgnoredError),
229232
),
230233
$unmatchedIgnoredError['realPath'],
231234
canBeIgnored: false,
232235
))->withIdentifier('ignore.unmatched');
233236
} elseif (!$onlyFiles) {
234237
$stringErrors[] = sprintf(
235-
'Ignored error pattern %s was not matched in reported errors.',
238+
'%s %s was not matched in reported errors.',
239+
IgnoredError::getIgnoredErrorLabel($unmatchedIgnoredError),
236240
IgnoredError::stringifyPattern($unmatchedIgnoredError),
237241
);
238242
}

tests/PHPStan/Analyser/AnalyserTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function testFileWithAnIgnoredErrorRawMessageAndWrongIdentifier(): void
9999
assert($result[0] instanceof Error);
100100
$this->assertSame('Fail.', $result[0]->getMessage());
101101
assert(is_string($result[1]));
102-
$this->assertSame('Ignored error pattern "Fail." (wrong.identifier) was not matched in reported errors.', $result[1]);
102+
$this->assertSame('Ignored error "Fail." (wrong.identifier) was not matched in reported errors.', $result[1]);
103103
}
104104

105105
public function testFileWithAnIgnoredWrongIdentifier(): void
@@ -721,7 +721,7 @@ public function testIgnoreErrorExplicitReportUnmatchedEnableRaw(): void
721721
];
722722
$result = $this->runAnalyser($ignoreErrors, false, __DIR__ . '/data/bootstrap.php', false);
723723
$this->assertCount(1, $result);
724-
$this->assertSame('Ignored error pattern "Fail." was not matched in reported errors.', $result[0]);
724+
$this->assertSame('Ignored error "Fail." was not matched in reported errors.', $result[0]);
725725
}
726726

727727
public function testIgnoreErrorExplicitReportUnmatchedEnableMulti(): void

0 commit comments

Comments
 (0)