diff --git a/src/Utils/Finder.php b/src/Utils/Finder.php index 0ef3b0c6f..900efe171 100644 --- a/src/Utils/Finder.php +++ b/src/Utils/Finder.php @@ -43,33 +43,30 @@ class Finder implements \IteratorAggregate /** * Begins search for files and directories matching mask. - * @param string ...$masks */ - public static function find(...$masks): static + public static function find(string|array $masks): static { - $masks = is_array($tmp = reset($masks)) ? $tmp : $masks; + $masks = is_array($masks) ? $masks : func_get_args(); // compatibility with variadic return (new static)->addMask($masks, 'dir')->addMask($masks, 'file'); } /** * Begins search for files matching mask. - * @param string ...$masks */ - public static function findFiles(...$masks): static + public static function findFiles(string|array $masks): static { - $masks = is_array($tmp = reset($masks)) ? $tmp : $masks; + $masks = is_array($masks) ? $masks : func_get_args(); // compatibility with variadic return (new static)->addMask($masks, 'file'); } /** * Begins search for directories matching mask. - * @param string ...$masks */ - public static function findDirectories(...$masks): static + public static function findDirectories(string|array $masks): static { - $masks = is_array($tmp = reset($masks)) ? $tmp : $masks; + $masks = is_array($masks) ? $masks : func_get_args(); // compatibility with variadic return (new static)->addMask($masks, 'dir'); } @@ -93,11 +90,10 @@ private function addMask(array $masks, string $type): static /** * Searches in the given directories. Wildcards are allowed. - * @param string ...$paths */ - public function in(...$paths): static + public function in(string|array $paths): static { - $paths = is_array($tmp = reset($paths)) ? $tmp : $paths; + $paths = is_array($paths) ? $paths : func_get_args(); // compatibility with variadic $this->addLocation($paths, ''); return $this; } @@ -105,11 +101,10 @@ public function in(...$paths): static /** * Searches recursively from the given directories. Wildcards are allowed. - * @param string ...$paths */ - public function from(...$paths): static + public function from(string|array $paths): static { - $paths = is_array($tmp = reset($paths)) ? $tmp : $paths; + $paths = is_array($paths) ? $paths : func_get_args(); // compatibility with variadic $this->addLocation($paths, '/**'); return $this; } @@ -142,11 +137,10 @@ public function childFirst(bool $state = true): static /** * Skips entries that matches the given masks relative to the ones defined with the in() or from() methods. - * @param string ...$masks */ - public function exclude(...$masks): static + public function exclude(string|array $masks): static { - $masks = is_array($tmp = reset($masks)) ? $tmp : $masks; + $masks = is_array($masks) ? $masks : func_get_args(); // compatibility with variadic foreach ($masks as $mask) { $mask = FileSystem::unixSlashes($mask); if (!preg_match('~^/?(\*\*/)?(.+)(/\*\*|/\*|/|)$~D', $mask, $m)) { diff --git a/tests/Utils/Finder.basic.phpt b/tests/Utils/Finder.basic.phpt index e7c9d6164..9712cdb4f 100644 --- a/tests/Utils/Finder.basic.phpt +++ b/tests/Utils/Finder.basic.phpt @@ -140,18 +140,3 @@ test('absolute path in mask', function () { // will not work if there are charac FileSystem::unixSlashes(__DIR__), ], export($finder)); }); - - -test('empty args', function () { - $finder = Finder::find()->in('fixtures.finder'); - Assert::same([], export($finder)); - - $finder = Finder::findFiles()->in('fixtures.finder'); - Assert::same([], export($finder)); - - $finder = Finder::findDirectories()->in('fixtures.finder'); - Assert::same([], export($finder)); - - $finder = Finder::find()->exclude()->in('fixtures.finder'); - Assert::same([], export($finder)); -});