From 5604666253fd46d11828a8a7a993e6e67be030ab Mon Sep 17 00:00:00 2001 From: Chris Kankiewicz Date: Mon, 13 Apr 2020 13:32:31 -0700 Subject: [PATCH] Made several closures static --- app/config/app.php | 4 ++-- app/src/Controllers/DirectoryController.php | 4 ++-- app/src/Factories/FinderFactory.php | 2 +- app/src/ViewFunctions/Breadcrumbs.php | 4 ++-- app/src/ViewFunctions/ParentUrl.php | 4 ++-- app/src/ViewFunctions/Url.php | 2 +- tests/Bootstrap/MiddlewareManagerTest.php | 2 +- tests/Factories/FinderFactoryTest.php | 4 ++-- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/config/app.php b/app/config/app.php index d0afb25..07fef6b 100644 --- a/app/config/app.php +++ b/app/config/app.php @@ -85,7 +85,7 @@ return [ * Default value: Array loaded from '.hidden' file if present, otherwise * an empty array ([]) */ - 'hidden_files' => function (ContainerInterface $container): array { + 'hidden_files' => static function (ContainerInterface $container): array { if (! is_readable($container->get('hidden_files_list'))) { return []; } @@ -158,7 +158,7 @@ return [ * * Default value: Array loaded from 'icons.php' config file */ - 'icons' => function (ContainerInterface $container): array { + 'icons' => static function (ContainerInterface $container): array { return require $container->get('icons_config'); }, ]; diff --git a/app/src/Controllers/DirectoryController.php b/app/src/Controllers/DirectoryController.php index 691ccab..3cd5e7c 100644 --- a/app/src/Controllers/DirectoryController.php +++ b/app/src/Controllers/DirectoryController.php @@ -89,9 +89,9 @@ class DirectoryController $readmes = (clone $files)->name('/^README(?:\..+)?$/i'); - $readmes->filter(function (SplFileInfo $file) { + $readmes->filter(static function (SplFileInfo $file) { return (bool) preg_match('/text\/.+/', mime_content_type($file->getPathname())); - })->sort(function (SplFileInfo $file1, SplFileInfo $file2) { + })->sort(static function (SplFileInfo $file1, SplFileInfo $file2) { return $file1->getExtension() <=> $file2->getExtension(); }); diff --git a/app/src/Factories/FinderFactory.php b/app/src/Factories/FinderFactory.php index 0c563fe..85eccfe 100644 --- a/app/src/Factories/FinderFactory.php +++ b/app/src/Factories/FinderFactory.php @@ -91,7 +91,7 @@ class FinderFactory $this->container->get('base_path') . '/' . $file, GLOB_BRACE | GLOB_NOSORT ); - })->flatten()->map(function (string $file): string { + })->flatten()->map(static function (string $file): string { return realpath($file); })->unique(); } diff --git a/app/src/ViewFunctions/Breadcrumbs.php b/app/src/ViewFunctions/Breadcrumbs.php index e1eba81..4901040 100644 --- a/app/src/ViewFunctions/Breadcrumbs.php +++ b/app/src/ViewFunctions/Breadcrumbs.php @@ -41,13 +41,13 @@ class Breadcrumbs extends ViewFunction { return Str::explode($path, $this->directorySeparator)->diff( explode($this->directorySeparator, $this->container->get('base_path')) - )->filter(function (string $crumb): bool { + )->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(function (string $path, string $name): string { + }, new Collection)->map(static function (string $path, string $name): string { return sprintf('?dir=%s', $path); }); } diff --git a/app/src/ViewFunctions/ParentUrl.php b/app/src/ViewFunctions/ParentUrl.php index 6dc6228..cc3e7c9 100644 --- a/app/src/ViewFunctions/ParentUrl.php +++ b/app/src/ViewFunctions/ParentUrl.php @@ -32,10 +32,10 @@ class ParentUrl extends ViewFunction public function __invoke(string $path) { $parentDir = Str::explode($path, $this->directorySeparator)->map( - function (string $segment): string { + static function (string $segment): string { return rawurlencode($segment); } - )->filter(function (?string $value): bool { + )->filter(static function (?string $value): bool { return $value !== null; })->slice(0, -1)->implode($this->directorySeparator); diff --git a/app/src/ViewFunctions/Url.php b/app/src/ViewFunctions/Url.php index 3fd8e09..20cdfab 100644 --- a/app/src/ViewFunctions/Url.php +++ b/app/src/ViewFunctions/Url.php @@ -56,7 +56,7 @@ class Url extends ViewFunction protected function escape(string $path): string { return Str::explode($path, $this->directorySeparator)->map( - function (string $segment): string { + static function (string $segment): string { return rawurlencode($segment); } )->implode($this->directorySeparator); diff --git a/tests/Bootstrap/MiddlewareManagerTest.php b/tests/Bootstrap/MiddlewareManagerTest.php index 0994ee1..278f3bb 100644 --- a/tests/Bootstrap/MiddlewareManagerTest.php +++ b/tests/Bootstrap/MiddlewareManagerTest.php @@ -16,7 +16,7 @@ class MiddlewareManagerTest extends TestCase public function test_it_registers_application_middlewares(): void { - $arguments = array_map(function (string $middleware): array { + $arguments = array_map(static function (string $middleware): array { return [$middleware]; }, self::MIDDLEWARES); diff --git a/tests/Factories/FinderFactoryTest.php b/tests/Factories/FinderFactoryTest.php index fedf4c2..0281ad1 100644 --- a/tests/Factories/FinderFactoryTest.php +++ b/tests/Factories/FinderFactoryTest.php @@ -30,7 +30,7 @@ class FinderFactoryTest extends TestCase public function test_it_can_sort_by_a_user_provided_closure(): void { $this->container->set('sort_order', \DI\value( - function (SplFileInfo $file1, SplFileInfo $file2) { + static function (SplFileInfo $file1, SplFileInfo $file2) { return $file1->getSize() <=> $file2->getSize(); } )); @@ -92,7 +92,7 @@ class FinderFactoryTest extends TestCase protected function getFilesArray(Finder $finder): array { - $files = array_map(function (SplFileInfo $file) { + $files = array_map(static function (SplFileInfo $file) { return $file->getFilename(); }, iterator_to_array($finder));