Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include identifier in generated baseline #844

Closed
wants to merge 1 commit into from
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
37 changes: 21 additions & 16 deletions src/Command/ErrorFormatter/BaselineNeonErrorFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,29 +40,34 @@ public function formatErrors(
if (!$fileSpecificError->canBeIgnored()) {
continue;
}
$fileErrors[$this->relativePathHelper->getRelativePath($fileSpecificError->getFilePath())][] = $fileSpecificError->getMessage();

$relativePath = $this->relativePathHelper->getRelativePath($fileSpecificError->getFilePath());
$key = $fileSpecificError->getIdentifier() . $fileSpecificError->getMessage();

$fileErrors[$relativePath][$key] ??= [
'message' => $fileSpecificError->getMessage(),
'count' => 0,
'identifier' => $fileSpecificError->getIdentifier()
];
$fileErrors[$relativePath][$key]['count']++;
}
ksort($fileErrors, SORT_STRING);

$errorsToOutput = [];
foreach ($fileErrors as $file => $errorMessages) {
$fileErrorsCounts = [];
foreach ($errorMessages as $errorMessage) {
if (!isset($fileErrorsCounts[$errorMessage])) {
$fileErrorsCounts[$errorMessage] = 1;
continue;
}
foreach ($fileErrors as $file => $fileSpecificErrors) {
ksort($fileSpecificErrors, SORT_STRING);

$fileErrorsCounts[$errorMessage]++;
}
ksort($fileErrorsCounts, SORT_STRING);

foreach ($fileErrorsCounts as $message => $count) {
$errorsToOutput[] = [
'message' => Helpers::escape('#^' . preg_quote($message, '#') . '$#'),
'count' => $count,
foreach ($fileSpecificErrors as $data) {
$error = [
'message' => Helpers::escape('#^' . preg_quote($data['message'], '#') . '$#'),
'count' => $data['count'],
'path' => Helpers::escape($file),
];
if ($data['identifier'] !== null && $data['identifier'] !== '') {
$error['identifier'] = Helpers::escape($data['identifier']);
}

$errorsToOutput[] = $error;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ public function outputOrderingProvider(): Generator
new Error('Error with Windows directory separators', 'TestFiles\\TestA', 1),
new Error('Error with Unix directory separators', 'TestFiles/TestA', 1),
new Error('Error without directory separators', 'TestFilesFoo', 1),
new Error('Error with identifier', 'TestFilesFoo', 1, true, null, null, null, null, null, 'my.identifier'),
];
yield [$errors];
mt_srand(0);
Expand Down Expand Up @@ -257,6 +258,12 @@ public function testOutputOrdering(array $errors): void
'count' => 1,
'path' => 'TestFilesFoo',
],
[
'message' => '#^Error with identifier$#',
'count' => 1,
'path' => 'TestFilesFoo',
'identifier' => 'my.identifier',
],
[
'message' => '#^A different error \\#1$#',
'count' => 1,
Expand Down