diff --git a/system/Autoloader/FileLocator.php b/system/Autoloader/FileLocator.php index 744567a3bcc0..92381a7ee25b 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) + ); + } }