Skip to content
Closed
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
14 changes: 7 additions & 7 deletions src/Analyser/Ignore/IgnoredError.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ public static function stringifyPattern($ignoredError): string
if (isset($ignoredError['message'])) {
$message = $ignoredError['message'];
}
if (isset($ignoredError['identifier'])) {
if ($message === '') {
$message = $ignoredError['identifier'];
} else {
$message = sprintf('%s (%s)', $message, $ignoredError['identifier']);
}
} elseif (isset($ignoredError['identifiers'])) {
if (isset($ignoredError['identifiers'])) {
$identifierList = implode(', ', $ignoredError['identifiers']);
if ($message === '') {
$message = $identifierList;
} else {
$message = sprintf('%s (%s)', $message, $identifierList);
}
} elseif (isset($ignoredError['identifier'])) {
if ($message === '') {
$message = $ignoredError['identifier'];
} else {
$message = sprintf('%s (%s)', $message, $ignoredError['identifier']);
}
}

if ($message === '') {
Expand Down
10 changes: 10 additions & 0 deletions tests/PHPStan/Analyser/AnalyserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ public function testFileWithAnIgnoredWrongIdentifier(): void
$this->assertSame('Ignored error pattern wrong.identifier was not matched in reported errors.', $result[1]);
}

public function testFileWithAnIgnoredWithIdentifierAndIdentifiers(): void
{
$result = $this->runAnalyser([['identifier' => 'some.identifier', 'identifiers' => ['wrong.identifiers']]], true, __DIR__ . '/data/bootstrap-error.php', false);
$this->assertCount(2, $result);
assert($result[0] instanceof Error);
$this->assertSame('Fail.', $result[0]->getMessage());
assert(is_string($result[1]));
$this->assertSame('Ignored error pattern wrong.identifiers was not matched in reported errors.', $result[1]);
}

public function testFileWithAnIgnoredErrorMessageAndCorrectIdentifier(): void
{
$result = $this->runAnalyser([['message' => '#Fail\.#', 'identifier' => 'tests.alwaysFail']], true, __DIR__ . '/data/bootstrap-error.php', false);
Expand Down
Loading