Browse Source

minor: displaying number of checked files (#6674)

Krzysztof Rewak 2 years ago
parent
commit
b577444c38

+ 1 - 1
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:

+ 1 - 0
src/Console/Command/FixCommand.php

@@ -315,6 +315,7 @@ EOF
 
         $reportSummary = new ReportSummary(
             $changed,
+            \count($finder),
             $fixEvent->getDuration(),
             $fixEvent->getMemory(),
             OutputInterface::VERBOSITY_VERBOSE <= $verbosity,

+ 9 - 0
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 @@ final class ReportSummary
         bool $isDecoratedOutput
     ) {
         $this->changed = $changed;
+        $this->filesCount = $filesCount;
         $this->time = $time;
         $this->memory = $memory;
         $this->addAppliedFixers = $addAppliedFixers;
@@ -85,6 +89,11 @@ final class ReportSummary
         return $this->time;
     }
 
+    public function getFilesCount(): int
+    {
+        return $this->filesCount;
+    }
+
     public function shouldAddAppliedFixers(): bool
     {
         return $this->addAppliedFixers;

+ 16 - 7
src/Console/Report/FixReport/TextReporter.php

@@ -38,10 +38,10 @@ final class TextReporter implements ReporterInterface
     {
         $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 @@ final class TextReporter implements ReporterInterface
             $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 @@ final class TextReporter implements ReporterInterface
         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
         );

+ 6 - 0
tests/Console/Report/FixReport/AbstractReporterTestCase.php

@@ -69,6 +69,7 @@ abstract class AbstractReporterTestCase extends TestCase
                 $this->createNoErrorReport(),
                 new ReportSummary(
                     [],
+                    10,
                     0,
                     0,
                     false,
@@ -85,6 +86,7 @@ abstract class AbstractReporterTestCase extends TestCase
                             'diff' => '',
                         ],
                     ],
+                    10,
                     0,
                     0,
                     false,
@@ -101,6 +103,7 @@ abstract class AbstractReporterTestCase extends TestCase
                             'diff' => 'this text is a diff ;)',
                         ],
                     ],
+                    10,
                     0,
                     0,
                     false,
@@ -117,6 +120,7 @@ abstract class AbstractReporterTestCase extends TestCase
                             'diff' => '',
                         ],
                     ],
+                    10,
                     0,
                     0,
                     true,
@@ -133,6 +137,7 @@ abstract class AbstractReporterTestCase extends TestCase
                             'diff' => '',
                         ],
                     ],
+                    10,
                     1234,
                     2621440, // 2.5 * 1024 * 1024
                     false,
@@ -153,6 +158,7 @@ abstract class AbstractReporterTestCase extends TestCase
                             'diff' => 'another diff here ;)',
                         ],
                     ],
+                    10,
                     1234,
                     2621440, // 2.5 * 1024 * 1024
                     true,

+ 3 - 0
tests/Console/Report/FixReport/ReportSummaryTest.php

@@ -32,6 +32,7 @@ final class ReportSummaryTest extends TestCase
                 'diff' => 'this text is a diff ;)',
             ],
         ];
+        $filesCount = 10;
         $time = time();
         $memory = 123456789;
         $addAppliedFixers = true;
@@ -40,6 +41,7 @@ final class ReportSummaryTest extends TestCase
 
         $reportSummary = new ReportSummary(
             $changed,
+            $filesCount,
             $time,
             $memory,
             $addAppliedFixers,
@@ -48,6 +50,7 @@ final class ReportSummaryTest extends TestCase
         );
 
         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());

+ 2 - 2
tests/Console/Report/FixReport/TextReporterTest.php

@@ -81,7 +81,7 @@ TEXT
             <<<'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 @@ another diff here ;)
 <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
         );

+ 1 - 1
tests/Smoke/CiIntegrationTest.php

@@ -194,7 +194,7 @@ Ignoring environment requirements because `PHP_CS_FIXER_IGNORE_ENV` is set. Exec
         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()
         );
     }

+ 1 - 1
tests/Smoke/StdinTest.php

@@ -75,7 +75,7 @@ final class StdinTest extends AbstractSmokeTest
     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
         );