From 3ddd0919f90e2139d5b32039625775e036fd77e8 Mon Sep 17 00:00:00 2001 From: Chris Kankiewicz Date: Mon, 16 Dec 2019 09:25:02 -0700 Subject: [PATCH] Extracted hidden files generation to a method in FinderComposer --- app/Bootstrap/FinderComposer.php | 39 ++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/app/Bootstrap/FinderComposer.php b/app/Bootstrap/FinderComposer.php index c3a2ba1..ada314a 100644 --- a/app/Bootstrap/FinderComposer.php +++ b/app/Bootstrap/FinderComposer.php @@ -21,29 +21,16 @@ class FinderComposer /** @var Container The application container */ protected $container; - /** @var Collection Collection of hidden file paths */ - protected $hiddenFiles; - /** - * Create a new FilesComposer object. + * Create a new FinderComposer object. * - * @param \PHLAK\Config\Config $config - * @param \Symfony\Component\Finder\Finder $finder + * @param \DI\Container $container + * @param \PHLAK\Config\Config $config */ public function __construct(Container $container, Config $config) { $this->container = $container; $this->config = $config; - - $this->hiddenFiles = Collection::make( - $this->config->get('hidden_files', []) - )->when($config->get('hide_app_files', true), function (Collection $collection) { - return $collection->merge(self::APP_FILES); - })->map(function (string $file) { - return glob($file, GLOB_BRACE | GLOB_NOSORT); - })->flatten()->map(function (string $file) { - return realpath($file); - }); } /** @@ -56,7 +43,7 @@ class FinderComposer $finder = Finder::create()->depth(0)->followLinks(); $finder->ignoreVCS($this->config->get('ignore_vcs_files', false)); $finder->filter(function (SplFileInfo $file) { - return ! $this->hiddenFiles->contains($file->getRealPath()); + return ! $this->hiddenFiles()->contains($file->getRealPath()); }); $sortOrder = $this->config->get('sort_order', 'name'); @@ -93,4 +80,22 @@ class FinderComposer $this->container->set(Finder::class, $finder); } + + /** + * Get a collection of hidden files. + * + * @return \Tightenco\Collect\Support\Collection + */ + protected function hiddenFiles(): Collection + { + return Collection::make( + $this->config->get('hidden_files', []) + )->when($this->config->get('hide_app_files', true), function (Collection $collection) { + return $collection->merge(self::APP_FILES); + })->map(function (string $file) { + return glob($file, GLOB_BRACE | GLOB_NOSORT); + })->flatten()->map(function (string $file) { + return realpath($file); + }); + } }