Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: replace $locator->getClassname() with findQualifiedNameFromPath() #8012

Merged
merged 5 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions system/CLI/Commands.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
7 changes: 6 additions & 1 deletion system/Config/BaseConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
12 changes: 10 additions & 2 deletions system/Config/BaseService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions system/Config/Factories.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
1 change: 1 addition & 0 deletions system/Filters/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand Down
4 changes: 2 additions & 2 deletions system/Publisher/Publisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
Loading