Skip to content

Commit dfda0ca

Browse files
committed
Finder: default mask is '*'
1 parent d4f51c2 commit dfda0ca

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

src/Utils/Finder.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class Finder implements \IteratorAggregate
5151
/**
5252
* Begins search for files and directories matching mask.
5353
*/
54-
public static function find(string|array $masks): static
54+
public static function find(string|array $masks = ['*']): static
5555
{
5656
$masks = is_array($masks) ? $masks : func_get_args(); // compatibility with variadic
5757
return (new static)->addMask($masks, 'dir')->addMask($masks, 'file');
@@ -61,7 +61,7 @@ public static function find(string|array $masks): static
6161
/**
6262
* Begins search for files matching mask.
6363
*/
64-
public static function findFiles(string|array $masks): static
64+
public static function findFiles(string|array $masks = ['*']): static
6565
{
6666
$masks = is_array($masks) ? $masks : func_get_args(); // compatibility with variadic
6767
return (new static)->addMask($masks, 'file');
@@ -71,7 +71,7 @@ public static function findFiles(string|array $masks): static
7171
/**
7272
* Begins search for directories matching mask.
7373
*/
74-
public static function findDirectories(string|array $masks): static
74+
public static function findDirectories(string|array $masks = ['*']): static
7575
{
7676
$masks = is_array($masks) ? $masks : func_get_args(); // compatibility with variadic
7777
return (new static)->addMask($masks, 'dir');
@@ -81,7 +81,7 @@ public static function findDirectories(string|array $masks): static
8181
/**
8282
* Finds files matching the specified masks.
8383
*/
84-
public function files(string|array $masks): static
84+
public function files(string|array $masks = ['*']): static
8585
{
8686
return $this->addMask((array) $masks, 'file');
8787
}
@@ -90,7 +90,7 @@ public function files(string|array $masks): static
9090
/**
9191
* Finds directories matching the specified masks.
9292
*/
93-
public function directories(string|array $masks): static
93+
public function directories(string|array $masks = ['*']): static
9494
{
9595
return $this->addMask((array) $masks, 'dir');
9696
}

tests/Utils/Finder.basic.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,24 @@ test('expty search', function () {
4242
});
4343

4444

45+
test('default mask', function () {
46+
$finder = Finder::find()->in('fixtures.finder');
47+
Assert::same(['fixtures.finder/file.txt', 'fixtures.finder/images', 'fixtures.finder/subdir'], export($finder));
48+
49+
$finder = Finder::findFiles()->in('fixtures.finder');
50+
Assert::same(['fixtures.finder/file.txt'], export($finder));
51+
52+
$finder = Finder::findDirectories()->in('fixtures.finder');
53+
Assert::same(['fixtures.finder/images', 'fixtures.finder/subdir'], export($finder));
54+
55+
$finder = (new Finder)->files()->in('fixtures.finder');
56+
Assert::same(['fixtures.finder/file.txt'], export($finder));
57+
58+
$finder = (new Finder)->directories()->in('fixtures.finder');
59+
Assert::same(['fixtures.finder/images', 'fixtures.finder/subdir'], export($finder));
60+
});
61+
62+
4563
test('current dir', function () {
4664
$finder = Finder::findFiles('fixtures.finder/*.txt');
4765
Assert::same(['fixtures.finder/file.txt'], export($finder));

0 commit comments

Comments
 (0)