Skip to content

Commit 33aa4a9

Browse files
[10.x] Move class from file logic in Console Kernel to dedicated method (#47665)
* Move class from file logic to dedicated method * formatting " --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent 8eb6ae8 commit 33aa4a9

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

src/Illuminate/Foundation/Console/Kernel.php

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Illuminate\Support\InteractsWithTime;
2121
use Illuminate\Support\Str;
2222
use ReflectionClass;
23+
use SplFileInfo;
2324
use Symfony\Component\Console\ConsoleEvents;
2425
use Symfony\Component\Console\Event\ConsoleCommandEvent;
2526
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
@@ -339,12 +340,8 @@ protected function load($paths)
339340

340341
$namespace = $this->app->getNamespace();
341342

342-
foreach ((new Finder)->in($paths)->files() as $command) {
343-
$command = $namespace.str_replace(
344-
['/', '.php'],
345-
['\\', ''],
346-
Str::after($command->getRealPath(), realpath(app_path()).DIRECTORY_SEPARATOR)
347-
);
343+
foreach ((new Finder)->in($paths)->files() as $file) {
344+
$command = $this->commandClassFromFile($file, $namespace);
348345

349346
if (is_subclass_of($command, Command::class) &&
350347
! (new ReflectionClass($command))->isAbstract()) {
@@ -355,6 +352,22 @@ protected function load($paths)
355352
}
356353
}
357354

355+
/**
356+
* Extract the command class name from the given file path.
357+
*
358+
* @param \SplFileInfo $file
359+
* @param string $namespace
360+
* @return string
361+
*/
362+
protected function commandClassFromFile(SplFileInfo $file, string $namespace): string
363+
{
364+
return $namespace.str_replace(
365+
['/', '.php'],
366+
['\\', ''],
367+
Str::after($file->getRealPath(), realpath(app_path()).DIRECTORY_SEPARATOR)
368+
);
369+
}
370+
358371
/**
359372
* Register the given command with the console application.
360373
*

0 commit comments

Comments
 (0)