Skip to content

Commit

Permalink
Don't throw if the directory does not exist
Browse files Browse the repository at this point in the history
If this was primarily a code API feature I would want this, but from our code (which is why we added this method) we want to be graceful if directories do not exist. If we throw, then we need to catch or add a precheck in a bunch of other places.
  • Loading branch information
caendesilva committed Dec 14, 2024
1 parent 481bb9f commit f2e2daf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/framework/src/Foundation/Kernel/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ public function smartGlob(string $pattern, int $flags = 0): Collection
/** @return \Illuminate\Support\Collection<int, string> */
public function findFiles(string $directory, string|array|false $matchExtensions = false, bool $recursive = false): Collection
{
if (! \Hyde\Facades\Filesystem::isDirectory($directory)) {
return collect();
}

$finder = Finder::create()->files()->in($this->path($directory));

if ($recursive === false) {
Expand Down
2 changes: 0 additions & 2 deletions packages/framework/tests/Unit/FilesystemFindFilesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Hyde\Testing\UnitTestCase;
use Hyde\Testing\CreatesTemporaryFiles;
use Hyde\Foundation\Kernel\Filesystem;
use Symfony\Component\Finder\Exception\DirectoryNotFoundException;

/**
* @covers \Hyde\Foundation\Kernel\Filesystem::findFiles
Expand Down Expand Up @@ -151,7 +150,6 @@ public function testFindFilesWithEmptyDirectory()

public function testFindFilesWithNonExistentDirectory()
{
$this->expectException(DirectoryNotFoundException::class);
$this->assertSameArray([], 'nonexistent-directory');
}

Expand Down

0 comments on commit f2e2daf

Please sign in to comment.