Skip to content

Commit a184db3

Browse files
authored
Merge pull request #136 from tighten/drift/improve-duster-glob-support
Improve Duster glob support using Symfony finder
2 parents eb0e339 + 581588c commit a184db3

File tree

9 files changed

+296
-115
lines changed

9 files changed

+296
-115
lines changed

app/Support/DusterConfig.php

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
namespace App\Support;
44

55
use App\Project;
6+
use Exception;
67
use Illuminate\Support\Arr;
8+
use Illuminate\Support\Str;
9+
use Symfony\Component\Finder\Finder;
710

811
class DusterConfig
912
{
@@ -63,11 +66,49 @@ public static function scopeConfigPaths(array $config): array
6366
*/
6467
public static function expandWildcards(array $paths): array
6568
{
66-
return collect($paths)->flatMap(function ($path) {
69+
return collect($paths)->flatMap(fn ($path) => static::globPath($path))->values()->toArray();
70+
}
71+
72+
/**
73+
* @return array<int, string>
74+
*/
75+
public static function globPath(string $path): array
76+
{
77+
try {
78+
// Finder uses forward slashes even on windows
79+
$path = Str::of($path)->replace('\\', '/')->__toString();
80+
81+
if (Str::of($path)->endsWith('.php')) {
82+
$name = Str::of($path)->afterLast('/');
83+
$path = Str::of($path)->beforeLast('/');
84+
85+
$files = (new Finder)
86+
->ignoreUnreadableDirs()
87+
->ignoreDotFiles(false)
88+
->files()
89+
->in($path);
90+
} else {
91+
$name = '.php';
92+
$files = (new Finder)
93+
->ignoreUnreadableDirs()
94+
->files()
95+
->in($path);
96+
}
97+
98+
return collect($files)
99+
->map(
100+
fn ($file) => Str::of($file->getPathName())->endsWith($name)
101+
// Fixes weird windows path issue with mixed slashes
102+
? Str::of($file->getPathName())->replace('\\', '/')->__toString()
103+
: null
104+
)
105+
->filter()
106+
->all();
107+
} catch (Exception) {
67108
return collect(glob($path, GLOB_NOCHECK))
68109
->filter(fn ($path) => file_exists($path))
69110
->all();
70-
})->toArray();
111+
}
71112
}
72113

73114
public function get(string $key, mixed $default = null): mixed

builds/duster

121 KB
Binary file not shown.

composer-dev.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
"php": "^8.1.0"
44
},
55
"require-dev": {
6-
"friendsofphp/php-cs-fixer": "^3.16.0",
7-
"laravel-zero/framework": "^10.0.0",
8-
"laravel/pint": "^1.9",
9-
"nunomaduro/larastan": "^2.2",
6+
"friendsofphp/php-cs-fixer": "^3.21.1",
7+
"laravel-zero/framework": "^10.1.1",
8+
"laravel/pint": "^v1.11.0",
9+
"larastan/larastan": "^2.7",
1010
"nunomaduro/termwind": "^1.15.1",
1111
"pestphp/pest": "^1.21.3",
1212
"rector/rector": "^0.15.10",
1313
"spatie/invade": "^1.1",
1414
"spatie/laravel-ray": "^1.31",
1515
"squizlabs/php_codesniffer": "^3.7",
16-
"tightenco/tlint": "^8.0"
16+
"tightenco/tlint": "^9.0"
1717
},
1818
"autoload": {
1919
"psr-4": {

0 commit comments

Comments
 (0)