Additional code cleanup

This commit is contained in:
Chris Kankiewicz
2025-03-18 11:21:34 -07:00
parent 9dcea73467
commit 1f36cf3e5d
7 changed files with 23 additions and 37 deletions

View File

@@ -32,9 +32,7 @@ class FinderFactory
$finder->ignoreDotFiles($this->config->get('hide_dot_files'));
if ($this->hiddenFiles->isNotEmpty()) {
$finder->filter(function (SplFileInfo $file): bool {
return ! $this->isHidden($file);
});
$finder->filter(fn (SplFileInfo $file): bool => ! $this->isHidden($file));
}
$sortOrder = $this->config->get('sort_order');

View File

@@ -48,12 +48,9 @@ class TranslationFactory
*/
protected function translations(): array
{
return $this->cache->get('translations', function (): array {
return array_values(array_map(static function (SplFileInfo $file): string {
return $file->getBasename('.yaml');
}, iterator_to_array(
Finder::create()->in($this->config->get('translations_path'))->name('*.yaml')
)));
});
return $this->cache->get('translations', fn (): array => array_values(array_map(
static fn (SplFileInfo $file): string => $file->getBasename('.yaml'),
iterator_to_array(Finder::create()->in($this->config->get('translations_path'))->name('*.yaml'))
)));
}
}

View File

@@ -27,14 +27,12 @@ class Breadcrumbs extends ViewFunction
{
return Str::explode($path, $this->directorySeparator)->diffAssoc(
explode($this->directorySeparator, $this->config->get('files_path'))
)->filter(static function (string $crumb): bool {
return ! in_array($crumb, [null, '.']);
})->reduce(function (Collection $carry, string $crumb): Collection {
return $carry->put($crumb, ltrim(
$carry->last() . $this->directorySeparator . rawurlencode($crumb), $this->directorySeparator
));
}, new Collection)->map(static function (string $path): string {
return sprintf('?dir=%s', $path);
});
)->filter(
static fn (string $crumb): bool => ! in_array($crumb, [null, '.'])
)->reduce(fn (Collection $carry, string $crumb): Collection => $carry->put($crumb, ltrim(
$carry->last() . $this->directorySeparator . rawurlencode($crumb), $this->directorySeparator
)), new Collection)->map(
static fn (string $path): string => sprintf('?dir=%s', $path)
);
}
}

View File

@@ -21,9 +21,7 @@ class Markdown extends ViewFunction
{
return $this->cache->get(
sprintf('markdown-%s', sha1($string)),
function () use ($string): string {
return (string) $this->converter->convert($string);
}
fn (): string => (string) $this->converter->convert($string)
);
}
}

View File

@@ -19,12 +19,10 @@ class ParentUrl extends ViewFunction
public function __invoke(string $path): string
{
$parentDir = Str::explode($path, $this->directorySeparator)->map(
static function (string $segment): string {
return rawurlencode($segment);
}
)->filter(static function (?string $value): bool {
return $value !== null;
})->slice(0, -1)->implode($this->directorySeparator);
static fn (string $segment): string => rawurlencode($segment)
)->filter(
static fn (?string $value): bool => $value !== null
)->slice(0, -1)->implode($this->directorySeparator);
if ($parentDir === '') {
return '.';

View File

@@ -53,9 +53,7 @@ class Url extends ViewFunction
protected function escape(string $path): string
{
return Str::explode($path, $this->directorySeparator)->map(
static function (string $segment): string {
return rawurlencode($segment);
}
static fn (string $segment): string => rawurlencode($segment)
)->implode($this->directorySeparator);
}
}

View File

@@ -42,9 +42,7 @@ class FinderFactoryTest extends TestCase
public function it_can_sort_by_a_user_provided_closure(): void
{
$this->container->set('sort_order', \DI\value(
static function (SplFileInfo $file1, SplFileInfo $file2) {
return $file1->getSize() <=> $file2->getSize();
}
static fn (SplFileInfo $file1, SplFileInfo $file2) => $file1->getSize() <=> $file2->getSize()
));
$finder = (new FinderFactory(
@@ -160,9 +158,10 @@ class FinderFactoryTest extends TestCase
protected function getFilesArray(Finder $finder): array
{
$files = array_map(static function (SplFileInfo $file) {
return $file->getFilename();
}, iterator_to_array($finder));
$files = array_map(
static fn (SplFileInfo $file): string => $file->getFilename(),
iterator_to_array($finder)
);
return array_values($files);
}