diff --git a/src/Utils/Finder.php b/src/Utils/Finder.php index a496528af..4c4150664 100644 --- a/src/Utils/Finder.php +++ b/src/Utils/Finder.php @@ -20,6 +20,9 @@ * ->from('.') * ->exclude('temp'); * + * @method static static find(string|array $masks = ['*']) + * @method static static findFiles(string|array $masks = ['*']) + * @method static static findFiles(string|array $masks = ['*']) * @implements \IteratorAggregate */ class Finder implements \IteratorAggregate @@ -48,10 +51,19 @@ class Finder implements \IteratorAggregate private bool $ignoreUnreadableDirs = true; + public static function __callStatic(string $name, array $args): mixed + { + if (in_array($name, ['find', 'findFiles', 'findDirectories'], true)) { + $name = '_' . $name; + return self::$name(...$args); + } + } + + /** * Begins search for files and directories matching mask. */ - public static function find(string|array $masks = ['*']): static + private static function _find(string|array $masks = ['*']): static { $masks = is_array($masks) ? $masks : func_get_args(); // compatibility with variadic return (new static)->addMask($masks, 'dir')->addMask($masks, 'file'); @@ -61,7 +73,7 @@ public static function find(string|array $masks = ['*']): static /** * Begins search for files matching mask. */ - public static function findFiles(string|array $masks = ['*']): static + private static function _findFiles(string|array $masks = ['*']): static { $masks = is_array($masks) ? $masks : func_get_args(); // compatibility with variadic return (new static)->addMask($masks, 'file'); @@ -71,7 +83,7 @@ public static function findFiles(string|array $masks = ['*']): static /** * Begins search for directories matching mask. */ - public static function findDirectories(string|array $masks = ['*']): static + private static function _findDirectories(string|array $masks = ['*']): static { $masks = is_array($masks) ? $masks : func_get_args(); // compatibility with variadic return (new static)->addMask($masks, 'dir'); diff --git a/tests/Utils/Finder.errors.phpt b/tests/Utils/Finder.errors.phpt index f84897e0c..91c34192b 100644 --- a/tests/Utils/Finder.errors.phpt +++ b/tests/Utils/Finder.errors.phpt @@ -38,3 +38,18 @@ test('globing', function () { "Directory './fixtures.finder/*/unknown' does not exist.", ); }); + + +test('wrong method', function () { + Assert::exception( + fn() => (new Finder)->findFiles('*'), + Nette\MemberAccessException::class, + 'Call to undefined method Nette\Utils\Finder::findFiles().', + ); + +/* prevents + ($finder = new Finder) + ->append() + ->findFiles('subdir*') +*/ +});