Skip to content

Commit

Permalink
minor: displaying number of checked files (#6674)
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysztofrewak committed Nov 5, 2022
1 parent bb94db0 commit b577444
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docker-compose.override.yaml.dist
Expand Up @@ -10,7 +10,7 @@ services:
extra_hosts:
# Required for Docker Linux until natively supported.
# See https://github.com/docker/for-linux/issues/264
host.docker.internal: 172.17.0.1
- 'host.docker.internal: 172.17.0.1'
php-8.0:
<<: *php
php-8.1:
Expand Down
1 change: 1 addition & 0 deletions src/Console/Command/FixCommand.php
Expand Up @@ -315,6 +315,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$reportSummary = new ReportSummary(
$changed,
\count($finder),
$fixEvent->getDuration(),
$fixEvent->getMemory(),
OutputInterface::VERBOSITY_VERBOSE <= $verbosity,
Expand Down
9 changes: 9 additions & 0 deletions src/Console/Report/FixReport/ReportSummary.php
Expand Up @@ -26,6 +26,8 @@ final class ReportSummary
*/
private array $changed;

private int $filesCount;

private int $time;

private int $memory;
Expand All @@ -43,13 +45,15 @@ final class ReportSummary
*/
public function __construct(
array $changed,
int $filesCount,
int $time,
int $memory,
bool $addAppliedFixers,
bool $isDryRun,
bool $isDecoratedOutput
) {
$this->changed = $changed;
$this->filesCount = $filesCount;
$this->time = $time;
$this->memory = $memory;
$this->addAppliedFixers = $addAppliedFixers;
Expand Down Expand Up @@ -85,6 +89,11 @@ public function getTime(): int
return $this->time;
}

public function getFilesCount(): int
{
return $this->filesCount;
}

public function shouldAddAppliedFixers(): bool
{
return $this->addAppliedFixers;
Expand Down
23 changes: 16 additions & 7 deletions src/Console/Report/FixReport/TextReporter.php
Expand Up @@ -38,10 +38,10 @@ public function generate(ReportSummary $reportSummary): string
{
$output = '';

$i = 0;
$identifiedFiles = 0;
foreach ($reportSummary->getChanged() as $file => $fixResult) {
++$i;
$output .= sprintf('%4d) %s', $i, $file);
++$identifiedFiles;
$output .= sprintf('%4d) %s', $identifiedFiles, $file);

if ($reportSummary->shouldAddAppliedFixers()) {
$output .= $this->getAppliedFixers(
Expand All @@ -54,7 +54,13 @@ public function generate(ReportSummary $reportSummary): string
$output .= PHP_EOL;
}

return $output.$this->getFooter($reportSummary->getTime(), $reportSummary->getMemory(), $reportSummary->isDryRun());
return $output.$this->getFooter(
$reportSummary->getTime(),
$identifiedFiles,
$reportSummary->getFilesCount(),
$reportSummary->getMemory(),
$reportSummary->isDryRun()
);
}

/**
Expand Down Expand Up @@ -83,15 +89,18 @@ private function getDiff(bool $isDecoratedOutput, string $diff): string
return PHP_EOL.$diffFormatter->format($diff).PHP_EOL;
}

private function getFooter(int $time, int $memory, bool $isDryRun): string
private function getFooter(int $time, int $identifiedFiles, int $files, int $memory, bool $isDryRun): string
{
if (0 === $time || 0 === $memory) {
return '';
}

return PHP_EOL.sprintf(
'%s all files in %.3f seconds, %.3f MB memory used'.PHP_EOL,
$isDryRun ? 'Checked' : 'Fixed',
'%s %d of %d %s in %.3f seconds, %.3f MB memory used'.PHP_EOL,
$isDryRun ? 'Found' : 'Fixed',
$identifiedFiles,
$files,
$isDryRun ? 'files that can be fixed' : 'files',
$time / 1000,
$memory / 1024 / 1024
);
Expand Down
6 changes: 6 additions & 0 deletions tests/Console/Report/FixReport/AbstractReporterTestCase.php
Expand Up @@ -69,6 +69,7 @@ final public function provideGenerateCases(): array
$this->createNoErrorReport(),
new ReportSummary(
[],
10,
0,
0,
false,
Expand All @@ -85,6 +86,7 @@ final public function provideGenerateCases(): array
'diff' => '',
],
],
10,
0,
0,
false,
Expand All @@ -101,6 +103,7 @@ final public function provideGenerateCases(): array
'diff' => 'this text is a diff ;)',
],
],
10,
0,
0,
false,
Expand All @@ -117,6 +120,7 @@ final public function provideGenerateCases(): array
'diff' => '',
],
],
10,
0,
0,
true,
Expand All @@ -133,6 +137,7 @@ final public function provideGenerateCases(): array
'diff' => '',
],
],
10,
1234,
2621440, // 2.5 * 1024 * 1024
false,
Expand All @@ -153,6 +158,7 @@ final public function provideGenerateCases(): array
'diff' => 'another diff here ;)',
],
],
10,
1234,
2621440, // 2.5 * 1024 * 1024
true,
Expand Down
3 changes: 3 additions & 0 deletions tests/Console/Report/FixReport/ReportSummaryTest.php
Expand Up @@ -32,6 +32,7 @@ public function testReportSummary(): void
'diff' => 'this text is a diff ;)',
],
];
$filesCount = 10;
$time = time();
$memory = 123456789;
$addAppliedFixers = true;
Expand All @@ -40,6 +41,7 @@ public function testReportSummary(): void

$reportSummary = new ReportSummary(
$changed,
$filesCount,
$time,
$memory,
$addAppliedFixers,
Expand All @@ -48,6 +50,7 @@ public function testReportSummary(): void
);

static::assertSame($changed, $reportSummary->getChanged());
static::assertSame($filesCount, $reportSummary->getFilesCount());
static::assertSame($time, $reportSummary->getTime());
static::assertSame($memory, $reportSummary->getMemory());
static::assertSame($addAppliedFixers, $reportSummary->shouldAddAppliedFixers());
Expand Down
4 changes: 2 additions & 2 deletions tests/Console/Report/FixReport/TextReporterTest.php
Expand Up @@ -81,7 +81,7 @@ protected function createWithTimeAndMemoryReport(): string
<<<'TEXT'
1) someFile.php
Fixed all files in 1.234 seconds, 2.500 MB memory used
Fixed 1 of 10 files in 1.234 seconds, 2.500 MB memory used
TEXT
);
Expand All @@ -104,7 +104,7 @@ protected function createComplexReport(): string
<comment> ----------- end diff -----------</comment>
Checked all files in 1.234 seconds, 2.500 MB memory used
Found 2 of 10 files that can be fixed in 1.234 seconds, 2.500 MB memory used
TEXT
);
Expand Down
2 changes: 1 addition & 1 deletion tests/Smoke/CiIntegrationTest.php
Expand Up @@ -194,7 +194,7 @@ public function testIntegration(
static::assertSame(substr_count($expectedResult3FilesDots, 'S'), substr_count($matches[1], 'S'));

static::assertMatchesRegularExpression(
'/^\s*Checked all files in \d+\.\d+ seconds, \d+\.\d+ MB memory used\s*$/',
'/^\s*Found \d+ of \d+ files that can be fixed in \d+\.\d+ seconds, \d+\.\d+ MB memory used\s*$/',
$result3->getOutput()
);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Smoke/StdinTest.php
Expand Up @@ -75,7 +75,7 @@ public function testFixingStdin(): void
private function unifyFooter(string $output): string
{
return preg_replace(
'/Checked all files in \d+\.\d+ seconds, \d+\.\d+ MB memory used/',
'/Found \d+ of \d+ files that can be fixed in \d+\.\d+ seconds, \d+\.\d+ MB memory used/',
'Footer',
$output
);
Expand Down

0 comments on commit b577444

Please sign in to comment.