Repository: PHP-CS-Fixer/PHP-CS-Fixer (PHP)

Issue:
Fatal error on PHP 8.1.13 using path-mode intersection
## Bug report

I encountered a problem running php-cs-fixer on PHP 8.1.13 using `path-mode` intersection. Here is the command I am running:

`php bin/php-cs-fixer fix --diff --dry-run -v --path-mode=intersection -- ./MyClass.php` which results in

```
Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, CallbackFilterIterator given in .../vendor/friendsofphp/php-cs-fixer/src/Console/Command/FixCommand.php:318
```

### Details

- PHP version: 8.1.13
- PHP CS Fixer version: 3.13.1



Discussion:
probably duplicate of #6715
@jschaedl don't know if that is really a duplicate. These are two different errors.
Fix released as [v3.13.2](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/releases/tag/v3.13.2)



Patch:
diff --git a/src/Console/Command/FixCommand.php b/src/Console/Command/FixCommand.php
index 3798c6dc116..b435c02884a 100644
--- a/src/Console/Command/FixCommand.php
+++ b/src/Console/Command/FixCommand.php
@@ -272,7 +272,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
         }
 
         $progressType = $resolver->getProgress();
-        $finder = $resolver->getFinder();
+        $finder = new \ArrayIterator(iterator_to_array($resolver->getFinder()));
 
         if (null !== $stdErr && $resolver->configFinderIsOverridden()) {
             $stdErr->writeln(
@@ -283,7 +283,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
         if ('none' === $progressType || null === $stdErr) {
             $progressOutput = new NullOutput();
         } else {
-            $finder = new \ArrayIterator(iterator_to_array($finder));
             $progressOutput = new ProcessOutput(
                 $stdErr,
                 $this->eventDispatcher,


Test patch:
diff --git a/tests/Console/Command/FixCommandTest.php b/tests/Console/Command/FixCommandTest.php
index faa85a493cb..f5b74ac2b8d 100644
--- a/tests/Console/Command/FixCommandTest.php
+++ b/tests/Console/Command/FixCommandTest.php
@@ -19,6 +19,7 @@
 use PhpCsFixer\Console\Command\FixCommand;
 use PhpCsFixer\Tests\TestCase;
 use PhpCsFixer\ToolInfo;
+use Symfony\Component\Console\Command\Command;
 use Symfony\Component\Console\Output\OutputInterface;
 use Symfony\Component\Console\Tester\CommandTester;
 
@@ -29,6 +30,19 @@
  */
 final class FixCommandTest extends TestCase
 {
+    public function testIntersectionPathMode(): void
+    {
+        $cmdTester = $this->doTestExecute([
+            '--path-mode' => 'intersection',
+            '--show-progress' => 'none',
+        ]);
+
+        static::assertSame(
+            Command::SUCCESS,
+            $cmdTester->getStatusCode()
+        );
+    }
+
     public function testEmptyRulesValue(): void
     {
         $this->expectException(
@@ -93,7 +107,7 @@ private function getDefaultArguments(): array
         return [
             'path' => [__FILE__],
             '--path-mode' => 'override',
-            '--allow-risky' => true,
+            '--allow-risky' => 'yes',
             '--dry-run' => true,
             '--using-cache' => 'no',
             '--show-progress' => 'none',