getHelper('question'); $passwordQuestion = new Question('Please enter the password: '); $passwordQuestion->setHidden(true); $passwordQuestion->setHiddenFallback(true); $passwordQuestion->setValidator(function (?string $value) { $password = trim($value); if (empty($password)) { throw new \Exception('The password may not be empty'); } return $value; }); $passwordQuestion->setMaxAttempts(3); return $helper->ask($input, $output, $passwordQuestion); } protected function validationError(ValidationFailedException $exception, SymfonyStyle $style): void { $errors = $exception->getViolations(); if ($errors->count() > 0) { /** @var \Symfony\Component\Validator\ConstraintViolation $error */ foreach ($errors as $error) { $style->error( $error->getPropertyPath() . ': ' . $error->getMessage() ); } } } }