From 535405241324aa387fcce24bee6e993f77f08156 Mon Sep 17 00:00:00 2001 From: Cole Thorsen <959538+colethorsen@users.noreply.github.com> Date: Tue, 14 Nov 2023 12:47:14 -0800 Subject: [PATCH 1/2] fix issue where running getClassName on a directory would cause a PHP error --- system/Autoloader/FileLocator.php | 4 ++++ tests/system/Autoloader/FileLocatorTest.php | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/system/Autoloader/FileLocator.php b/system/Autoloader/FileLocator.php index 744567a3bcc0..7cd2a5e60135 100644 --- a/system/Autoloader/FileLocator.php +++ b/system/Autoloader/FileLocator.php @@ -119,6 +119,10 @@ public function locateFile(string $file, ?string $folder = null, string $ext = ' */ public function getClassname(string $file): string { + if(is_dir($file)) { + return ''; + } + $php = file_get_contents($file); $tokens = token_get_all($php); $dlm = false; diff --git a/tests/system/Autoloader/FileLocatorTest.php b/tests/system/Autoloader/FileLocatorTest.php index 1cf32cfa5ad1..8df13094ef7a 100644 --- a/tests/system/Autoloader/FileLocatorTest.php +++ b/tests/system/Autoloader/FileLocatorTest.php @@ -312,4 +312,12 @@ public function testGetClassNameFromNonClassFile(): void $this->locator->getClassname(SYSTEMPATH . 'bootstrap.php') ); } + + public function testGetClassNameFromDirectory(): void + { + $this->assertSame( + '', + $this->locator->getClassname(SYSTEMPATH) + ); + } } From 3ba7ef65cd6d1b5dca7b97bc1b93d95a4139c9ab Mon Sep 17 00:00:00 2001 From: Cole Thorsen <959538+colethorsen@users.noreply.github.com> Date: Wed, 15 Nov 2023 07:51:19 -0800 Subject: [PATCH 2/2] fix style --- system/Autoloader/FileLocator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Autoloader/FileLocator.php b/system/Autoloader/FileLocator.php index 7cd2a5e60135..92381a7ee25b 100644 --- a/system/Autoloader/FileLocator.php +++ b/system/Autoloader/FileLocator.php @@ -119,7 +119,7 @@ public function locateFile(string $file, ?string $folder = null, string $ext = ' */ public function getClassname(string $file): string { - if(is_dir($file)) { + if (is_dir($file)) { return ''; }