diff --git a/app/Bootstrap/FinderComposer.php b/app/Bootstrap/FinderComposer.php index 5d18b56..cf694f1 100644 --- a/app/Bootstrap/FinderComposer.php +++ b/app/Bootstrap/FinderComposer.php @@ -15,6 +15,16 @@ class FinderComposer /** @const Application paths to be hidden */ protected const APP_FILES = ['app', 'node_modules', 'vendor', 'index.php']; + /** @const Array of sort options mapped to their respective methods */ + public const SORT_METHODS = [ + 'accessed' => SortMethods\Accessed::class, + 'changed' => SortMethods\Changed::class, + 'modified' => SortMethods\Modified::class, + 'name' => SortMethods\Name::class, + 'natural' => SortMethods\Natural::class, + 'type' => SortMethods\Type::class, + ]; + /** @var Config Application config */ protected $config; @@ -50,28 +60,12 @@ class FinderComposer if ($sortOrder instanceof Closure) { $finder->sort($sortOrder); } else { - switch ($sortOrder) { - case 'accessed': - $finder->sortByAccessedTime(); - break; - case 'changed': - $finder->sortByChangedTime(); - break; - case 'modified': - $finder->sortByModifiedTime(); - break; - case 'name': - $finder->sortByName(); - break; - case 'natural': - $finder->sortByName(true); - break; - case 'type': - $finder->sortByType(); - break; - default: - throw new RuntimeException("Invalid sort option '{$sortOrder}'"); + if (! array_key_exists($sortOrder, self::SORT_METHODS)) { + throw new RuntimeException("Invalid sort option '{$sortOrder}'"); } + + $sortMethod = self::SORT_METHODS[$sortOrder]; + call_user_func(new $sortMethod, $finder); } if ($this->config->get('app.reverse_sort', false)) { diff --git a/app/Bootstrap/SortMethods/Accessed.php b/app/Bootstrap/SortMethods/Accessed.php new file mode 100644 index 0000000..96d01a8 --- /dev/null +++ b/app/Bootstrap/SortMethods/Accessed.php @@ -0,0 +1,20 @@ +sortByAccessedTime(); + } +} diff --git a/app/Bootstrap/SortMethods/Changed.php b/app/Bootstrap/SortMethods/Changed.php new file mode 100644 index 0000000..097d217 --- /dev/null +++ b/app/Bootstrap/SortMethods/Changed.php @@ -0,0 +1,20 @@ +sortByChangedTime(); + } +} diff --git a/app/Bootstrap/SortMethods/Modified.php b/app/Bootstrap/SortMethods/Modified.php new file mode 100644 index 0000000..c4c0afa --- /dev/null +++ b/app/Bootstrap/SortMethods/Modified.php @@ -0,0 +1,20 @@ +sortByModifiedTime(); + } +} diff --git a/app/Bootstrap/SortMethods/Name.php b/app/Bootstrap/SortMethods/Name.php new file mode 100644 index 0000000..29ffa00 --- /dev/null +++ b/app/Bootstrap/SortMethods/Name.php @@ -0,0 +1,20 @@ +sortByName(); + } +} diff --git a/app/Bootstrap/SortMethods/Natural.php b/app/Bootstrap/SortMethods/Natural.php new file mode 100644 index 0000000..da9db8a --- /dev/null +++ b/app/Bootstrap/SortMethods/Natural.php @@ -0,0 +1,20 @@ +sortByName(true); + } +} diff --git a/app/Bootstrap/SortMethods/SortMethod.php b/app/Bootstrap/SortMethods/SortMethod.php new file mode 100644 index 0000000..6f7b3e7 --- /dev/null +++ b/app/Bootstrap/SortMethods/SortMethod.php @@ -0,0 +1,17 @@ +sortByType(); + } +}