From a56d9b2d5e56702232192a12aa5a89557ede1764 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Thu, 31 Oct 2024 12:00:00 +0000 Subject: [PATCH] Return an empty array if there is no ignore file --- src/IgnoreFile.php | 4 ++++ tests/Kernel/IgnoreFileTest.php | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/src/IgnoreFile.php b/src/IgnoreFile.php index 40c3822..30ff2e6 100644 --- a/src/IgnoreFile.php +++ b/src/IgnoreFile.php @@ -10,6 +10,10 @@ final class IgnoreFile public static function parse(): array { + if (@stat(self::FILENAME) === false) { + return []; + } + return explode("\n", file_get_contents(self::FILENAME)); } } diff --git a/tests/Kernel/IgnoreFileTest.php b/tests/Kernel/IgnoreFileTest.php index 4dafefc..4a85329 100644 --- a/tests/Kernel/IgnoreFileTest.php +++ b/tests/Kernel/IgnoreFileTest.php @@ -18,4 +18,9 @@ class IgnoreFileTest extends KernelTestCase self::assertSame(['phpstan.neon.dist'], IgnoreFile::parse()); } + + public function test_it_returns_an_empty_array_of_filenames_if_there_is_no_ignore_file(): void + { + self::assertSame([], IgnoreFile::parse()); + } }