*/ #[\Override] protected function promptForMissingArgumentsUsing(): array { return [ 'identifier' => fn (): int | string => search( label: 'Search client (by name, ID, identifier, or slug):', placeholder: 'Type client name, identifier or slug...', options: fn (string $value): array => $this->clientResolver->searchOptions($value), scroll: 10, ), ]; } #[\Override] public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void { parent::complete($input, $suggestions); if ($input->mustSuggestArgumentValuesFor('identifier')) { $this->clientResolver->complete($suggestions); } } public function handle( RegenerateClientSecret $usecase, UsecaseExecutor $executor, ): int { $client = $this->resolveClient(); if ($client === null) { return self::FAILURE; } if (! $this->confirmRegeneration($client)) { $this->warn('Secret regeneration cancelled.'); return self::SUCCESS; } try { $input = $this->getInput($client); $view = UsecaseBuilder::using($executor) ->do($usecase) ->from($input) ->with(new RegenerateClientSecretPresenter()) ->run(); $this->displayResult($client, $view); return self::SUCCESS; } catch (ClientNotFoundException | \InvalidArgumentException $e) { $this->error($e->getMessage()); return self::FAILURE; } } private function getInput(Client $client): Input { return new Input($client->id); } private function resolveClient(): ?Client { $raw = $this->argument('identifier'); if (! is_string($raw) || trim($raw) === '') { $this->error('No client specified.'); return null; } $inputString = trim($raw); $client = $this->clientResolver->find($inputString); if ($client !== null) { return $client; } try { new ClientIdentifier($inputString); $this->error("Client '{$inputString}' not found."); } catch (\InvalidArgumentException) { $this->error("Invalid client identifier '{$inputString}'. Expected a valid client identifier."); } return null; } private function confirmRegeneration(Client $client): bool { $this->newLine(); $this->warn(sprintf("Regenerating the secret will immediately invalidate the existing secret for client '%s'.", $client->name->value)); return confirm( label: 'Do you want to proceed?', default: false, ); } private function displayResult(Client $client, RegenerateClientSecretView $view): void { $this->newLine(); $this->info($view->message); $this->newLine(); $this->table( ['Field', 'Value'], [ ['ID', $client->id->value], ['Name', $client->name->value], ['Identifier', $view->identifier], ['New Secret', $view->secret], ], ); $this->newLine(); $this->warn('WARNING: Store the new secret securely, it cannot be retrieved later.'); } }