diff --git a/phpstan-baseline.php b/phpstan-baseline.php index 8fa88e921662..9529cc9e1f7f 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -951,11 +951,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/Config/DotEnv.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Only booleans are allowed in &&, string given on the left side\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Config/Factories.php', -]; $ignoreErrors[] = [ 'message' => '#^Only booleans are allowed in a negated boolean, array given\\.$#', 'count' => 1, diff --git a/system/CLI/Commands.php b/system/CLI/Commands.php index df28e533a354..caa404bcfe74 100644 --- a/system/CLI/Commands.php +++ b/system/CLI/Commands.php @@ -100,9 +100,9 @@ public function discoverCommands() // Loop over each file checking to see if a command with that // alias exists in the class. foreach ($files as $file) { - $className = $locator->getClassname($file); + $className = $locator->findQualifiedNameFromPath($file); - if ($className === '' || ! class_exists($className)) { + if ($className === false || ! class_exists($className)) { continue; } diff --git a/system/Config/BaseConfig.php b/system/Config/BaseConfig.php index 87166737e746..178d7ce5ca92 100644 --- a/system/Config/BaseConfig.php +++ b/system/Config/BaseConfig.php @@ -211,7 +211,12 @@ protected function registerProperties() $registrarsFiles = $locator->search('Config/Registrar.php'); foreach ($registrarsFiles as $file) { - $className = $locator->getClassname($file); + $className = $locator->findQualifiedNameFromPath($file); + + if ($className === false) { + continue; + } + static::$registrars[] = new $className(); } diff --git a/system/Config/BaseService.php b/system/Config/BaseService.php index b66b8c9f535e..a15c67806479 100644 --- a/system/Config/BaseService.php +++ b/system/Config/BaseService.php @@ -343,7 +343,11 @@ protected static function discoverServices(string $name, array $arguments) // Get instances of all service classes and cache them locally. foreach ($files as $file) { - $classname = $locator->getClassname($file); + $classname = $locator->findQualifiedNameFromPath($file); + + if ($classname === false) { + continue; + } if (! in_array($classname, [Services::class], true)) { static::$services[] = new $classname(); @@ -380,7 +384,11 @@ protected static function buildServicesCache(): void // Get instances of all service classes and cache them locally. foreach ($files as $file) { - $classname = $locator->getClassname($file); + $classname = $locator->findQualifiedNameFromPath($file); + + if ($classname === false) { + continue; + } if ($classname !== Services::class) { self::$serviceNames[] = $classname; diff --git a/system/Config/Factories.php b/system/Config/Factories.php index a32df02725ac..2857fdf06520 100644 --- a/system/Config/Factories.php +++ b/system/Config/Factories.php @@ -297,9 +297,9 @@ class_exists($alias, false) // Check all files for a valid class foreach ($files as $file) { - $class = $locator->getClassname($file); + $class = $locator->findQualifiedNameFromPath($file); - if ($class && self::verifyInstanceOf($options, $class)) { + if ($class !== false && self::verifyInstanceOf($options, $class)) { return $class; } } diff --git a/system/Filters/Filters.php b/system/Filters/Filters.php index 665db2e01792..95a38f313303 100644 --- a/system/Filters/Filters.php +++ b/system/Filters/Filters.php @@ -139,6 +139,7 @@ private function discoverFilters(): void $files = $locator->search('Config/Filters.php'); foreach ($files as $file) { + // The $file may not be a class file. $className = $locator->getClassname($file); // Don't include our main Filter config again... diff --git a/system/Publisher/Publisher.php b/system/Publisher/Publisher.php index e40a14c88905..064dd354e8ba 100644 --- a/system/Publisher/Publisher.php +++ b/system/Publisher/Publisher.php @@ -114,9 +114,9 @@ final public static function discover(string $directory = 'Publishers'): array // Loop over each file checking to see if it is a Publisher foreach (array_unique($files) as $file) { - $className = $locator->getClassname($file); + $className = $locator->findQualifiedNameFromPath($file); - if ($className !== '' && class_exists($className) && is_a($className, self::class, true)) { + if ($className !== false && class_exists($className) && is_a($className, self::class, true)) { self::$discovered[$directory][] = new $className(); } }