askForClientName(); if (! $this->confirmCreation($clientName)) { $this->warn('Client creation cancelled.'); return self::SUCCESS; } $view = UsecaseBuilder::using($executor) ->do($usecase) ->from($this->getInput($clientName)) ->with(new CreateClientPresenter()) ->run(); $this->displayCredentials($view); return self::SUCCESS; } private function getInput(ClientName $clientName): Input { return new Input($clientName); } private function askForClientName(): ClientName { $rawName = text( label: 'Client name (e.g. "Ones Branding website")', placeholder: 'E.g. Ones Branding website', required: 'Client name cannot be empty.', validate: function (string $value): ?string { $trimmed = trim($value); if ($trimmed === '') { return 'Client name cannot be empty.'; } try { $clientName = new ClientName($trimmed); if ($this->clientRepository->existsByName($clientName)) { return ClientNameAlreadyExistsException::forName($trimmed)->getMessage(); } } catch (\InvalidArgumentException $e) { return $e->getMessage(); } return null; }, ); return new ClientName(trim($rawName)); } private function confirmCreation(ClientName $name): bool { $this->newLine(); $this->info('Summary:'); $this->table( ['Field', 'Value'], [ ['Name', $name->value], ['Identifier', ''], ['Secret', ''], ['Status', 'Active'], ], ); return confirm( label: 'Create this API client?', default: false, ); } private function displayCredentials(CreateClientView $view): void { $this->newLine(); $this->info($view->message); $this->newLine(); $this->table( ['Field', 'Value'], [ ['ID', $view->id], ['Name', $view->name], ['Identifier', $view->identifier], ['Secret', $view->secret], ], ); $this->newLine(); $this->warn('WARNING: Store the secret securely, it cannot be retrieved later.'); } }