Skip to content

Commit

Permalink
Fix PHP baseline count
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Oct 3, 2024
1 parent 1249a20 commit 32d8aa7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
26 changes: 15 additions & 11 deletions src/Command/ErrorFormatter/BaselinePhpErrorFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
use PHPStan\Command\AnalysisResult;
use PHPStan\Command\Output;
use PHPStan\File\RelativePathHelper;
use function array_keys;
use function count;
use function ksort;
use function preg_quote;
use function sort;
use function sprintf;
use function var_export;
use const SORT_STRING;
Expand Down Expand Up @@ -53,41 +51,47 @@ public function formatErrors(
$fileErrorsByMessage = [];
foreach ($errors as $error) {
$errorMessage = $error->getMessage();
$identifier = $error->getIdentifier();
if (!isset($fileErrorsByMessage[$errorMessage])) {
$fileErrorsByMessage[$errorMessage] = [
1,
$error->getIdentifier() !== null ? [$error->getIdentifier() => true] : [],
$identifier !== null ? [$identifier => 1] : [],
];
continue;
}

$fileErrorsByMessage[$errorMessage][0]++;

if ($error->getIdentifier() === null) {
if ($identifier === null) {
continue;
}
$fileErrorsByMessage[$errorMessage][1][$error->getIdentifier()] = true;

if (!isset($fileErrorsByMessage[$errorMessage][1][$identifier])) {
$fileErrorsByMessage[$errorMessage][1][$identifier] = 1;
continue;
}

$fileErrorsByMessage[$errorMessage][1][$identifier]++;
}
ksort($fileErrorsByMessage, SORT_STRING);

foreach ($fileErrorsByMessage as $message => [$count, $identifiersInKeys]) {
$identifiers = array_keys($identifiersInKeys);
sort($identifiers);
foreach ($fileErrorsByMessage as $message => [$totalCount, $identifiers]) {
ksort($identifiers, SORT_STRING);
if (count($identifiers) > 0) {
foreach ($identifiers as $identifier) {
foreach ($identifiers as $identifier => $identifierCount) {
$php .= sprintf(
"\$ignoreErrors[] = [\n\t'message' => %s,\n\t'identifier' => %s,\n\t'count' => %d,\n\t'path' => __DIR__ . %s,\n];\n",
var_export(Helpers::escape('#^' . preg_quote($message, '#') . '$#'), true),
var_export(Helpers::escape($identifier), true),
var_export($count, true),
var_export($identifierCount, true),
var_export(Helpers::escape($file), true),
);
}
} else {
$php .= sprintf(
"\$ignoreErrors[] = [\n\t'message' => %s,\n\t'count' => %d,\n\t'path' => __DIR__ . %s,\n];\n",
var_export(Helpers::escape('#^' . preg_quote($message, '#') . '$#'), true),
var_export($count, true),
var_export($totalCount, true),
var_export(Helpers::escape($file), true),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ public function dataFormatErrors(): iterable
\$ignoreErrors[] = [
'message' => '#^Foo with same message, different identifier$#',
'identifier' => 'argument.byRef',
'count' => 2,
'count' => 1,
'path' => __DIR__ . '/Foo.php',
];
\$ignoreErrors[] = [
'message' => '#^Foo with same message, different identifier$#',
'identifier' => 'argument.type',
'count' => 2,
'count' => 1,
'path' => __DIR__ . '/Foo.php',
];
Expand Down

0 comments on commit 32d8aa7

Please sign in to comment.