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

minor: displaying number of checked files #6674

Merged
merged 7 commits into from
Nov 5, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker-compose.override.yaml.dist
Original file line number Diff line number Diff line change
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
3 changes: 2 additions & 1 deletion src/Console/Command/FixCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public function getHelp(): string
* 64 - Exception raised within the application.

EOF
;
;
julienfalque marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down 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
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ final class ReportSummary
*/
private array $changed;

private int $files;

private int $time;

private int $memory;
Expand All @@ -43,13 +45,15 @@ final class ReportSummary
*/
public function __construct(
array $changed,
int $files,
int $time,
int $memory,
bool $addAppliedFixers,
bool $isDryRun,
bool $isDecoratedOutput
) {
$this->changed = $changed;
$this->files = $files;
$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 getFiles(): int
julienfalque marked this conversation as resolved.
Show resolved Hide resolved
{
return $this->files;
}

public function shouldAddAppliedFixers(): bool
{
return $this->addAppliedFixers;
Expand Down
15 changes: 8 additions & 7 deletions src/Console/Report/FixReport/TextReporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ 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(), count($reportSummary->getChanged()), $reportSummary->getFiles(), $reportSummary->getMemory(), $reportSummary->isDryRun());
julienfalque marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down Expand Up @@ -83,17 +83,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 $changed, 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',
$time / 1000,
$memory / 1024 / 1024
);
'%s %d files in %.3f seconds, %.3f MB memory used'.PHP_EOL,
$isDryRun ? 'Checked' : sprintf('Fixed %d of', $changed),
$files,
$time / 1000,
$memory / 1024 / 1024
);
julienfalque marked this conversation as resolved.
Show resolved Hide resolved
}
}
6 changes: 6 additions & 0 deletions tests/Console/Report/FixReport/AbstractReporterTestCase.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function testReportSummary(): void
'diff' => 'this text is a diff ;)',
],
];
$files = 10;
$time = time();
$memory = 123456789;
$addAppliedFixers = true;
Expand All @@ -40,6 +41,7 @@ public function testReportSummary(): void

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

static::assertSame($changed, $reportSummary->getChanged());
static::assertSame($files, $reportSummary->getFiles());
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
Original file line number Diff line number Diff line change
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
Checked 10 files in 1.234 seconds, 2.500 MB memory used
julienfalque marked this conversation as resolved.
Show resolved Hide resolved

TEXT
);
Expand Down
2 changes: 1 addition & 1 deletion tests/Smoke/CiIntegrationTest.php
Original file line number Diff line number Diff line change
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*Checked \d+ files in \d+\.\d+ seconds, \d+\.\d+ MB memory used\s*$/',
$result3->getOutput()
);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Smoke/StdinTest.php
Original file line number Diff line number Diff line change
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/',
'/Checked \d+ files in \d+\.\d+ seconds, \d+\.\d+ MB memory used/',
'Footer',
$output
);
Expand Down