Skip to content
This repository was archived by the owner on Nov 23, 2025. It is now read-only.

Commit dde459e

Browse files
committed
coding style
1 parent ad0e470 commit dde459e

File tree

3 files changed

+8
-20
lines changed

3 files changed

+8
-20
lines changed

src/Utils/Finder.php

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,9 @@ private function select(array $masks, string $type): self
9494
{
9595
$this->cursor = &$this->groups[];
9696
$pattern = self::buildPattern($masks);
97-
$this->filter(function (RecursiveDirectoryIterator $file) use ($type, $pattern): bool {
98-
return !$file->isDot()
97+
$this->filter(fn(RecursiveDirectoryIterator $file): bool => !$file->isDot()
9998
&& $file->$type()
100-
&& (!$pattern || preg_match($pattern, '/' . strtr($file->getSubPathName(), '\\', '/')));
101-
});
99+
&& (!$pattern || preg_match($pattern, '/' . strtr($file->getSubPathName(), '\\', '/'))));
102100
return $this;
103101
}
104102

@@ -163,7 +161,7 @@ private static function buildPattern(array $masks): ?string
163161
}
164162
$pattern[] = $prefix . strtr(
165163
preg_quote($mask, '#'),
166-
['\*\*' => '.*', '\*' => '[^/]*', '\?' => '[^/]', '\[\!' => '[^', '\[' => '[', '\]' => ']', '\-' => '-']
164+
['\*\*' => '.*', '\*' => '[^/]*', '\?' => '[^/]', '\[\!' => '[^', '\[' => '[', '\]' => ']', '\-' => '-'],
167165
);
168166
}
169167
return $pattern ? '#/(' . implode('|', $pattern) . ')$#Di' : null;
@@ -261,9 +259,7 @@ public function exclude(...$masks): self
261259
$masks = $masks && is_array($masks[0]) ? $masks[0] : $masks;
262260
$pattern = self::buildPattern($masks);
263261
if ($pattern) {
264-
$this->filter(function (RecursiveDirectoryIterator $file) use ($pattern): bool {
265-
return !preg_match($pattern, '/' . strtr($file->getSubPathName(), '\\', '/'));
266-
});
262+
$this->filter(fn(RecursiveDirectoryIterator $file): bool => !preg_match($pattern, '/' . strtr($file->getSubPathName(), '\\', '/')));
267263
}
268264
return $this;
269265
}
@@ -308,9 +304,7 @@ public function size(string $operator, int $size = null): self
308304
$size *= $units[strtolower($unit)];
309305
$operator = $operator ?: '=';
310306
}
311-
return $this->filter(function (RecursiveDirectoryIterator $file) use ($operator, $size): bool {
312-
return self::compare($file->getSize(), $operator, $size);
313-
});
307+
return $this->filter(fn(RecursiveDirectoryIterator $file): bool => self::compare($file->getSize(), $operator, $size));
314308
}
315309

316310

@@ -330,9 +324,7 @@ public function date(string $operator, $date = null): self
330324
$operator = $operator ?: '=';
331325
}
332326
$date = DateTime::from($date)->format('U');
333-
return $this->filter(function (RecursiveDirectoryIterator $file) use ($operator, $date): bool {
334-
return self::compare($file->getMTime(), $operator, $date);
335-
});
327+
return $this->filter(fn(RecursiveDirectoryIterator $file): bool => self::compare($file->getMTime(), $operator, $date));
336328
}
337329

338330

tests/Utils/Finder.basic.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ test('getSubPathName', function () {
116116
}
117117
Assert::same(
118118
['file.txt', 'subdir/file.txt', 'subdir/subdir2/file.txt'],
119-
export($res)
119+
export($res),
120120
);
121121
});
122122

tests/Utils/Finder.filters.phpt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,7 @@ test('date filter', function () {
6262

6363

6464
test('custom filters', function () {
65-
Finder::extensionMethod('length', function ($finder, $length) {
66-
return $finder->filter(function ($file) use ($length) {
67-
return strlen($file->getFilename()) == $length;
68-
});
69-
});
65+
Finder::extensionMethod('length', fn($finder, $length) => $finder->filter(fn($file) => strlen($file->getFilename()) == $length));
7066
});
7167

7268

0 commit comments

Comments
 (0)