diff --git a/src/System/Integrate/Console/HelpCommand.php b/src/System/Integrate/Console/HelpCommand.php index 64d60bbc..47476b23 100644 --- a/src/System/Integrate/Console/HelpCommand.php +++ b/src/System/Integrate/Console/HelpCommand.php @@ -8,7 +8,6 @@ use System\Console\Style\Style; use System\Console\Traits\PrintHelpTrait; use System\Integrate\Application; -use System\Integrate\ConfigRepository; use System\Integrate\ValueObjects\CommandMap; use System\Text\Str; @@ -261,9 +260,6 @@ public function commandHelp(): int */ private function commandMaps() { - return array_map( - static fn ($command): CommandMap => new CommandMap($command), - Application::getIntance()[ConfigRepository::class]->get('commands', []) - ); + return Util::loadCommandFromConfig(Application::getIntance()); } } diff --git a/src/System/Integrate/Console/Karnel.php b/src/System/Integrate/Console/Karnel.php index 8d25c1c4..1c495995 100644 --- a/src/System/Integrate/Console/Karnel.php +++ b/src/System/Integrate/Console/Karnel.php @@ -4,13 +4,11 @@ namespace System\Integrate\Console; -use DI\Container; use System\Console\Style\Style; use System\Integrate\Application; use System\Integrate\Bootstrap\BootProviders; use System\Integrate\Bootstrap\ConfigProviders; use System\Integrate\Bootstrap\RegisterProviders; -use System\Integrate\ConfigRepository; use System\Integrate\ValueObjects\CommandMap; class Karnel @@ -168,13 +166,10 @@ public function exit_code() /** * Command route. * - * @return \System\Integrate\ValueObjects\CommandMap[] + * @return CommandMap[] */ - protected function commands() + protected function commands(): array { - return array_map( - static fn ($command): CommandMap => new CommandMap($command), - $this->app[ConfigRepository::class]->get('commands', []) - ); + return Util::loadCommandFromConfig($this->app); } } diff --git a/src/System/Integrate/Console/Util.php b/src/System/Integrate/Console/Util.php new file mode 100644 index 00000000..beb06bc9 --- /dev/null +++ b/src/System/Integrate/Console/Util.php @@ -0,0 +1,29 @@ +get('commands', []) as $commands) { + foreach ($commands as $command) { + $command_map[] = new CommandMap($command); + } + } + + return $command_map; + } +} diff --git a/tests/Integrate/Commands/HelpCommandsTest.php b/tests/Integrate/Commands/HelpCommandsTest.php index b7f31468..cd8748b4 100644 --- a/tests/Integrate/Commands/HelpCommandsTest.php +++ b/tests/Integrate/Commands/HelpCommandsTest.php @@ -16,7 +16,7 @@ protected function setUp(): void { parent::setUp(); $this->app->set('config', fn () => new ConfigRepository([ - 'commands' => $this->command, + 'commands' => [$this->command], ])); } diff --git a/tests/Integrate/Console/KarnelTest.php b/tests/Integrate/Console/KarnelTest.php index 47b6ba42..e9ad1c0b 100644 --- a/tests/Integrate/Console/KarnelTest.php +++ b/tests/Integrate/Console/KarnelTest.php @@ -226,7 +226,7 @@ public function itCanCallCommand() class NormalCommand extends Karnel { - protected function commands() + protected function commands(): array { return [ // olr style