Facade.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php declare(strict_types=1);
  2. /*
  3. * This file is part of phpunit/php-file-iterator.
  4. *
  5. * (c) Sebastian Bergmann <sebastian@phpunit.de>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace SebastianBergmann\FileIterator;
  11. use function array_unique;
  12. use function assert;
  13. use function sort;
  14. use SplFileInfo;
  15. /**
  16. * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
  17. */
  18. final class Facade
  19. {
  20. /**
  21. * @psalm-param list<non-empty-string>|non-empty-string $paths
  22. * @psalm-param list<non-empty-string>|string $suffixes
  23. * @psalm-param list<non-empty-string>|string $prefixes
  24. * @psalm-param list<non-empty-string> $exclude
  25. *
  26. * @psalm-return list<non-empty-string>
  27. */
  28. public function getFilesAsArray(array|string $paths, array|string $suffixes = '', array|string $prefixes = '', array $exclude = []): array
  29. {
  30. $iterator = (new Factory)->getFileIterator($paths, $suffixes, $prefixes, $exclude);
  31. $files = [];
  32. foreach ($iterator as $file) {
  33. assert($file instanceof SplFileInfo);
  34. $file = $file->getRealPath();
  35. if ($file) {
  36. $files[] = $file;
  37. }
  38. }
  39. $files = array_unique($files);
  40. sort($files);
  41. return $files;
  42. }
  43. }