Skip to content

Fix error count by type #33

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

Merged
merged 2 commits into from
Jan 20, 2025
Merged
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
3 changes: 2 additions & 1 deletion src/BaselinePerIdentifierFormatter.php
Original file line number Diff line number Diff line change
@@ -73,6 +73,7 @@ public function formatErrors(

foreach ($fileErrors as $identifier => $errors) {
$errorsToOutput = [];
$errorsCount = 0;

foreach ($errors as $file => $errorMessages) {
$fileErrorsCounts = [];
@@ -94,12 +95,12 @@ public function formatErrors(
'count' => $count,
'path' => NeonHelper::escape($file),
];
$errorsCount += $count;
}
}

$includes[] = $identifier . '.neon';
$baselineFilePath = $this->baselinesDir . '/' . $identifier . '.neon';
$errorsCount = count($errorsToOutput);

$output->writeLineFormatted(sprintf('Writing baseline file %s with %d errors', $baselineFilePath, $errorsCount));

4 changes: 2 additions & 2 deletions src/BaselineSplitter.php
Original file line number Diff line number Diff line change
@@ -5,8 +5,8 @@
use ShipMonk\PHPStan\Baseline\Exception\ErrorException;
use ShipMonk\PHPStan\Baseline\Handler\HandlerFactory;
use SplFileInfo;
use function array_reduce;
use function assert;
use function count;
use function dirname;
use function file_put_contents;
use function is_array;
@@ -62,7 +62,7 @@ public function split(string $loaderFilePath): array
foreach ($groupedErrors as $identifier => $errors) {
$fileName = $identifier . '.' . $extension;
$filePath = $folder . '/' . $fileName;
$errorsCount = count($errors);
$errorsCount = array_reduce($errors, static fn(int $carry, array $item): int => $carry + $item['count'], 0);

$outputInfo[$filePath] = $errorsCount;
$baselineFiles[] = $fileName;
1 change: 1 addition & 0 deletions tests/Rule/BaselinePerIdentifierFormatterTest.php
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@ public function testFormat(): void
$this->createAnalysisResult(
[
(new Error('Error simple', $fakeRoot . '/app/file.php', 1))->withIdentifier('sample.identifier'), // @phpstan-ignore phpstanApi.constructor
(new Error('Error simple', $fakeRoot . '/app/file.php', 5))->withIdentifier('sample.identifier'), // @phpstan-ignore phpstanApi.constructor
(new Error('Error to escape \'#', $fakeRoot . '/app/config.php', 2))->withIdentifier('another.identifier'), // @phpstan-ignore phpstanApi.constructor
(new Error('Error 3', $fakeRoot . '/app/index.php', 3)), // @phpstan-ignore phpstanApi.constructor
],
4 changes: 2 additions & 2 deletions tests/Rule/data/baselines-neon/sample.identifier.neon
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# total 1 error
# total 2 errors

parameters:
ignoreErrors:
-
message: '#^Error simple$#'
count: 1
count: 2
path: ../app/file.php
4 changes: 2 additions & 2 deletions tests/Rule/data/baselines-php/sample.identifier.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php declare(strict_types = 1);

// total 1 error
// total 2 errors

$ignoreErrors = [];
$ignoreErrors[] = [
'message' => '#^Error simple$#',
'count' => 1,
'count' => 2,
'path' => __DIR__ . '/../app/file.php',
];

4 changes: 2 additions & 2 deletions tests/SplitterTest.php
Original file line number Diff line number Diff line change
@@ -61,7 +61,7 @@ public function testSplitter(): void
self::assertSame([
$folder . '/baselines/another.identifier.neon' => 1,
$folder . '/baselines/missing-identifier.neon' => 1,
$folder . '/baselines/sample.identifier.neon' => 1,
$folder . '/baselines/sample.identifier.neon' => 2,
$folder . '/baselines/loader.neon' => null,
], $written);
}
@@ -84,7 +84,7 @@ private function getSampleErrors(): array
'ignoreErrors' => [
[
'message' => '#^Error simple$#',
'count' => 1,
'count' => 2,
'path' => '../app/file.php',
'identifier' => 'sample.identifier',
],