Repository: symfony/symfony
File: src/Symfony/Component/Finder/Finder.php (PHP)

Code before:
    }

    /**
     * Appends an existing set of files/directories to the finder.
     *
     * The set can be another Finder, an Iterator, an IteratorAggregate, or even a plain array.
     *
     * @param iterable<SplFileInfo|\SplFileInfo|string> $iterator
     *
     * @return $this
     */
    public function append(iterable $iterator): static
    {
        if ($iterator instanceof self) {
            $this->iterators[] = $iterator->getIterator();
        } else {
            /** @var \ArrayIterator<string, SplFileInfo> $it */
            $it = new \ArrayIterator();
            foreach ($iterator as $file) {
                if ($file instanceof SplFileInfo) {
                    $it[$file->getPathname()] = $file;
                } elseif ($file instanceof \SplFileInfo) {
                    $it[$file->getPathname()] = new SplFileInfo(
                        $file->getPathname(),
                        $file->getPath(),
                        $file->getPathname(),
                    );
                } else {
                    $file = new \SplFileInfo($file);
                    $it[$file->getPathname()] = new SplFileInfo(
                        $file->getPathname(),
                        $file->getPath(),
                        $file->getPathname(),
                    );
                }
            }
            $this->iterators[] = $it;
        }

        return $this;
    }

    /**
     * Check if any results were found.
     */
    public function hasResults(): bool
    {
        foreach ($this->getIterator() as $_) {
            return true;
        }


Review comment (bug):
I do not believe this produces proper results.
While the Symfony\Finder\SplFileInfo interface would now be respected, produced content is different than when using only `->in(...)`.

I run following script in https://github.com/PHP-CS-Fixer/PHP-CS-Fixer repo:


```php
<?php

declare(strict_types=1);

use Symfony\Component\Finder\Finder;

include 'vendor/autoload.php';

$FILE = './src/Linter/LinterInterface.php';
$f = new \SplFileInfo($FILE);

var_dump([ # 1
    "---" => "RAW_FILE",
    "getPathname" => $f->getPathname(),
    "getPath" => $f->getPath(),
]);

var_dump("/////");

$finder = Finder::create()
    ->in(__DIR__.'/src/')
    // ->append([$FILE]) << no, let it be found by `->in(...)`
;

$files = iterator_to_array($finder->getIterator());
$f = $files[realpath($FILE)];

var_dump([ # 2
    "::class" => get_class($f), // \Symfony\Component\Finder\SplFileInfo
    "getPathname" => $f->getPathname(),
    "getRelativePath" => $f->getRelativePath(),
    "getRelativePathname" => $f->getRelativePathname(),
]);

var_dump("/////");

$finder = Finder::create()
    ->in(__DIR__.'/src/')
    ->append([$FILE])
;

$files = iterator_to_array($finder->getIterator());
$f = $files[$FILE];

var_dump([ # 3
    "::class" => get_class($f), // \SplFileInfo
    "getPathname" => $f->getPathname(),
    "getRelativePath (mocked)" => $f->getPath(),
    "getRelativePathname (mocked)" => $f->getPathname(),
]);

```


as you can see, var_dump#3 is failing to recognise `relativePath` in context of `->in(__DIR__.'/src/'), while var_dump#2 is not having this problem
```sh
keradus@machine PHP-CS-Fixer_3 % php -f x.php
array(3) {
  ["---"]=>
  string(8) "RAW_FILE"
  ["getPathname"]=>
  string(32) "./src/Linter/LinterInterface.php"
  ["getPath"]=>
  string(12) "./src/Linter"
}
string(5) "/////"
array(4) {
  ["::class"]=>
  string(36) "Symfony\Component\Finder\SplFileInfo"
  ["getPathname"]=>
  string(76) "/Users/keradus/github/PHP-CS-Fixer_3/src/Linter/LinterInterface.php"
  ["getRelativePath"]=>
  string(6) "Linter"
  ["getRelativePathname"]=>
  string(26) "Linter/LinterInterface.php"
}
string(5) "/////"
array(4) {
  ["::class"]=>
  string(11) "SplFileInfo"
  ["getPathname"]=>
  string(32) "./src/Linter/LinterInterface.php"
  ["getRelativePath (mocked)"]=>
  string(12) "./src/Linter"
  ["getRelativePathname (mocked)"]=>
  string(32) "./src/Linter/LinterInterface.php"
}

```

Code after:
        }

        if ($this->sort || $this->reverseSorting) {
            $iterator = (new SortableIterator($iterator, $this->sort, $this->reverseSorting))->getIterator();
        }

        return $iterator;
    }

    /**
     * Appends an existing set of files/directories to the finder.
     *
     * The set can be another Finder, an Iterator, an IteratorAggregate, or even a plain array.
     *
     * @param iterable<SplFileInfo|\SplFileInfo|string> $iterator
     *
     * @return $this
     */
    public function append(iterable $iterator): static
    {
        $this->iterators[] = $iterator;

        return $this;
    }

    /**
     * Check if any results were found.
     */
    public function hasResults(): bool
    {
        foreach ($this->getIterator() as $_) {
            return true;
        }

        return false;
    }

    /**
     * Counts all the results collected by the iterators.
     */
    public function count(): int
    {
        return iterator_count($this->getIterator());
    }

    private function searchInDirectory(string $dir): \Iterator
    {
        $exclude = $this->exclude;
        $notPaths = $this->notPaths;

        if ($this->pruneFilters) {