Skip to content

Commit d5ad48e

Browse files
authored
Merge pull request #8012 from kenjis/perf-replace-locator-getClassname
perf: replace $locator->getClassname() with findQualifiedNameFromPath()
2 parents 1277cae + d3b5c17 commit d5ad48e

File tree

7 files changed

+23
-14
lines changed

7 files changed

+23
-14
lines changed

phpstan-baseline.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -951,11 +951,6 @@
951951
'count' => 1,
952952
'path' => __DIR__ . '/system/Config/DotEnv.php',
953953
];
954-
$ignoreErrors[] = [
955-
'message' => '#^Only booleans are allowed in &&, string given on the left side\\.$#',
956-
'count' => 1,
957-
'path' => __DIR__ . '/system/Config/Factories.php',
958-
];
959954
$ignoreErrors[] = [
960955
'message' => '#^Only booleans are allowed in a negated boolean, array given\\.$#',
961956
'count' => 1,

system/CLI/Commands.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ public function discoverCommands()
100100
// Loop over each file checking to see if a command with that
101101
// alias exists in the class.
102102
foreach ($files as $file) {
103-
$className = $locator->getClassname($file);
103+
$className = $locator->findQualifiedNameFromPath($file);
104104

105-
if ($className === '' || ! class_exists($className)) {
105+
if ($className === false || ! class_exists($className)) {
106106
continue;
107107
}
108108

system/Config/BaseConfig.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,12 @@ protected function registerProperties()
211211
$registrarsFiles = $locator->search('Config/Registrar.php');
212212

213213
foreach ($registrarsFiles as $file) {
214-
$className = $locator->getClassname($file);
214+
$className = $locator->findQualifiedNameFromPath($file);
215+
216+
if ($className === false) {
217+
continue;
218+
}
219+
215220
static::$registrars[] = new $className();
216221
}
217222

system/Config/BaseService.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,11 @@ protected static function discoverServices(string $name, array $arguments)
343343

344344
// Get instances of all service classes and cache them locally.
345345
foreach ($files as $file) {
346-
$classname = $locator->getClassname($file);
346+
$classname = $locator->findQualifiedNameFromPath($file);
347+
348+
if ($classname === false) {
349+
continue;
350+
}
347351

348352
if (! in_array($classname, [Services::class], true)) {
349353
static::$services[] = new $classname();
@@ -380,7 +384,11 @@ protected static function buildServicesCache(): void
380384

381385
// Get instances of all service classes and cache them locally.
382386
foreach ($files as $file) {
383-
$classname = $locator->getClassname($file);
387+
$classname = $locator->findQualifiedNameFromPath($file);
388+
389+
if ($classname === false) {
390+
continue;
391+
}
384392

385393
if ($classname !== Services::class) {
386394
self::$serviceNames[] = $classname;

system/Config/Factories.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,9 @@ class_exists($alias, false)
297297

298298
// Check all files for a valid class
299299
foreach ($files as $file) {
300-
$class = $locator->getClassname($file);
300+
$class = $locator->findQualifiedNameFromPath($file);
301301

302-
if ($class && self::verifyInstanceOf($options, $class)) {
302+
if ($class !== false && self::verifyInstanceOf($options, $class)) {
303303
return $class;
304304
}
305305
}

system/Filters/Filters.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ private function discoverFilters(): void
139139
$files = $locator->search('Config/Filters.php');
140140

141141
foreach ($files as $file) {
142+
// The $file may not be a class file.
142143
$className = $locator->getClassname($file);
143144

144145
// Don't include our main Filter config again...

system/Publisher/Publisher.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ final public static function discover(string $directory = 'Publishers'): array
114114

115115
// Loop over each file checking to see if it is a Publisher
116116
foreach (array_unique($files) as $file) {
117-
$className = $locator->getClassname($file);
117+
$className = $locator->findQualifiedNameFromPath($file);
118118

119-
if ($className !== '' && class_exists($className) && is_a($className, self::class, true)) {
119+
if ($className !== false && class_exists($className) && is_a($className, self::class, true)) {
120120
self::$discovered[$directory][] = new $className();
121121
}
122122
}

0 commit comments

Comments
 (0)