From 3962817003c3ca5d6aec749894dd5facfc92069c Mon Sep 17 00:00:00 2001 From: Jannik Zschiesche Date: Tue, 4 Jun 2024 10:53:20 +0200 Subject: [PATCH] Improve implementation --- src/Command/InitializeCommand.php | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/src/Command/InitializeCommand.php b/src/Command/InitializeCommand.php index 2f08458..ba09a79 100644 --- a/src/Command/InitializeCommand.php +++ b/src/Command/InitializeCommand.php @@ -59,6 +59,7 @@ protected function execute (InputInterface $input, OutputInterface $output) : in } $type = $input->getArgument("type"); + \assert(null === $type || \is_string($type)); if (!\in_array($type, self::ALLOWED_TYPES, true)) { @@ -74,18 +75,11 @@ protected function execute (InputInterface $input, OutputInterface $output) : in try { - $initializer = match ($type) + return match ($type) { - "symfony" => new SymfonyInitializer(), - "library" => new LibraryInitializer(), + "symfony" => (new SymfonyInitializer())->initialize($io), + "library" => (new LibraryInitializer())->initialize($io), }; - - if (null === $initializer) - { - return $this->printError($io, $type); - } - - return $initializer->initialize($io); } catch (\Throwable $exception) { @@ -93,14 +87,4 @@ protected function execute (InputInterface $input, OutputInterface $output) : in return 2; } } - - /** - * Prints an error - */ - private function printError (TorrStyle $io, string $type) : int - { - $io->error("Unknown type: {$type}"); - - return self::FAILURE; - } }