From b577444c38b61f2fdc32cd0a4685bd595be391b7 Mon Sep 17 00:00:00 2001 From: Krzysztof Rewak Date: Sat, 5 Nov 2022 10:57:50 +0100 Subject: [PATCH] minor: displaying number of checked files (#6674) --- docker-compose.override.yaml.dist | 2 +- src/Console/Command/FixCommand.php | 1 + .../Report/FixReport/ReportSummary.php | 9 ++++++++ src/Console/Report/FixReport/TextReporter.php | 23 +++++++++++++------ .../FixReport/AbstractReporterTestCase.php | 6 +++++ .../Report/FixReport/ReportSummaryTest.php | 3 +++ .../Report/FixReport/TextReporterTest.php | 4 ++-- tests/Smoke/CiIntegrationTest.php | 2 +- tests/Smoke/StdinTest.php | 2 +- 9 files changed, 40 insertions(+), 12 deletions(-) diff --git a/docker-compose.override.yaml.dist b/docker-compose.override.yaml.dist index ef6e3e4199f..01ca93d1425 100644 --- a/docker-compose.override.yaml.dist +++ b/docker-compose.override.yaml.dist @@ -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: diff --git a/src/Console/Command/FixCommand.php b/src/Console/Command/FixCommand.php index 5180af75a87..3798c6dc116 100644 --- a/src/Console/Command/FixCommand.php +++ b/src/Console/Command/FixCommand.php @@ -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, diff --git a/src/Console/Report/FixReport/ReportSummary.php b/src/Console/Report/FixReport/ReportSummary.php index 851d4cb3c26..ccdfefb3225 100644 --- a/src/Console/Report/FixReport/ReportSummary.php +++ b/src/Console/Report/FixReport/ReportSummary.php @@ -26,6 +26,8 @@ final class ReportSummary */ private array $changed; + private int $filesCount; + private int $time; private int $memory; @@ -43,6 +45,7 @@ final class ReportSummary */ public function __construct( array $changed, + int $filesCount, int $time, int $memory, bool $addAppliedFixers, @@ -50,6 +53,7 @@ public function __construct( bool $isDecoratedOutput ) { $this->changed = $changed; + $this->filesCount = $filesCount; $this->time = $time; $this->memory = $memory; $this->addAppliedFixers = $addAppliedFixers; @@ -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; diff --git a/src/Console/Report/FixReport/TextReporter.php b/src/Console/Report/FixReport/TextReporter.php index 35b479a9c54..6de741bc2a8 100644 --- a/src/Console/Report/FixReport/TextReporter.php +++ b/src/Console/Report/FixReport/TextReporter.php @@ -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( @@ -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() + ); } /** @@ -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 ); diff --git a/tests/Console/Report/FixReport/AbstractReporterTestCase.php b/tests/Console/Report/FixReport/AbstractReporterTestCase.php index 57371cd38e5..43ee42b7b35 100644 --- a/tests/Console/Report/FixReport/AbstractReporterTestCase.php +++ b/tests/Console/Report/FixReport/AbstractReporterTestCase.php @@ -69,6 +69,7 @@ final public function provideGenerateCases(): array $this->createNoErrorReport(), new ReportSummary( [], + 10, 0, 0, false, @@ -85,6 +86,7 @@ final public function provideGenerateCases(): array 'diff' => '', ], ], + 10, 0, 0, false, @@ -101,6 +103,7 @@ final public function provideGenerateCases(): array 'diff' => 'this text is a diff ;)', ], ], + 10, 0, 0, false, @@ -117,6 +120,7 @@ final public function provideGenerateCases(): array 'diff' => '', ], ], + 10, 0, 0, true, @@ -133,6 +137,7 @@ final public function provideGenerateCases(): array 'diff' => '', ], ], + 10, 1234, 2621440, // 2.5 * 1024 * 1024 false, @@ -153,6 +158,7 @@ final public function provideGenerateCases(): array 'diff' => 'another diff here ;)', ], ], + 10, 1234, 2621440, // 2.5 * 1024 * 1024 true, diff --git a/tests/Console/Report/FixReport/ReportSummaryTest.php b/tests/Console/Report/FixReport/ReportSummaryTest.php index f72ccccdcc2..f8156487468 100644 --- a/tests/Console/Report/FixReport/ReportSummaryTest.php +++ b/tests/Console/Report/FixReport/ReportSummaryTest.php @@ -32,6 +32,7 @@ public function testReportSummary(): void 'diff' => 'this text is a diff ;)', ], ]; + $filesCount = 10; $time = time(); $memory = 123456789; $addAppliedFixers = true; @@ -40,6 +41,7 @@ public function testReportSummary(): void $reportSummary = new ReportSummary( $changed, + $filesCount, $time, $memory, $addAppliedFixers, @@ -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()); diff --git a/tests/Console/Report/FixReport/TextReporterTest.php b/tests/Console/Report/FixReport/TextReporterTest.php index a84935cf81e..4145ef7afba 100644 --- a/tests/Console/Report/FixReport/TextReporterTest.php +++ b/tests/Console/Report/FixReport/TextReporterTest.php @@ -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 ); @@ -104,7 +104,7 @@ protected function createComplexReport(): string ----------- end diff ----------- -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 ); diff --git a/tests/Smoke/CiIntegrationTest.php b/tests/Smoke/CiIntegrationTest.php index 7680f4ed0d0..cb79c07c1cd 100644 --- a/tests/Smoke/CiIntegrationTest.php +++ b/tests/Smoke/CiIntegrationTest.php @@ -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() ); } diff --git a/tests/Smoke/StdinTest.php b/tests/Smoke/StdinTest.php index ac6184aac73..ee0e5904d55 100644 --- a/tests/Smoke/StdinTest.php +++ b/tests/Smoke/StdinTest.php @@ -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 );