From eb29b449d01325e219e84c6035e5105d5062703b Mon Sep 17 00:00:00 2001 From: konradoboza Date: Tue, 27 Aug 2024 16:45:05 +0200 Subject: [PATCH] cr remarks vol1 --- phpstan-baseline.neon | 5 +++ src/bundle/Command/UpdateUserCommand.php | 40 +++++++++++++++++------- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index e7981c9..3f9b34d 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -10,6 +10,11 @@ parameters: count: 1 path: src/bundle/Command/AuditUserDatabaseCommand.php + - + message: "#^Negated boolean expression is always false\\.$#" + count: 1 + path: src/bundle/Command/UpdateUserCommand.php + - message: "#^Method Ibexa\\\\Bundle\\\\User\\\\Controller\\\\Controller\\:\\:performAccessCheck\\(\\) has no return type specified\\.$#" count: 1 diff --git a/src/bundle/Command/UpdateUserCommand.php b/src/bundle/Command/UpdateUserCommand.php index 390a629..fba0aca 100644 --- a/src/bundle/Command/UpdateUserCommand.php +++ b/src/bundle/Command/UpdateUserCommand.php @@ -26,9 +26,8 @@ final class UpdateUserCommand extends Command public function __construct( private readonly UserService $userService, private readonly Repository $repository, - ?string $name = null ) { - parent::__construct($name); + parent::__construct(); } protected function configure(): void @@ -42,7 +41,7 @@ protected function configure(): void 'password', null, InputOption::VALUE_NONE, - 'New plaintext password (input will be in a "hidden" mode)', + 'New plaintext password (input will be in a "hidden" mode)' ); $this->addOption( 'email', @@ -64,6 +63,19 @@ protected function configure(): void ); } + protected function interact(InputInterface $input, OutputInterface $output): void + { + $io = new SymfonyStyle($input, $output); + $password = $input->getOption('password'); + + if (!$password) { + return; + } + + $password = $io->askHidden('Password (your input will be hidden)'); + $input->setOption('password', $password); + } + /** * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException @@ -79,9 +91,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int $email = $input->getOption('email'); if (!$password && !$enable && !$disable && $email === null) { - $io->success('No new user data specified, exiting.'); + $io->error('No new user data specified, exiting.'); - return Command::SUCCESS; + return Command::FAILURE; } $user = $this->userService->loadUserByLogin($userReference); @@ -92,15 +104,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int return Command::FAILURE; } - if ($password) { - $password = $io->askHidden('Password (your input will be hidden)'); - $input->setOption('password', $password); - } - $userUpdateStruct = new UserUpdateStruct(); - $userUpdateStruct->password = $input->getOption('password'); + $userUpdateStruct->password = null; $userUpdateStruct->email = $email; - $userUpdateStruct->enabled = $enable === true || !$disable; + $userUpdateStruct->enabled = $this->resolveEnabledFlag($enable, $disable); $this->repository->sudo( function () use ($user, $userUpdateStruct): User { @@ -112,4 +119,13 @@ function () use ($user, $userUpdateStruct): User { return Command::SUCCESS; } + + private function resolveEnabledFlag(bool $enable, bool $disable): ?bool + { + if (!$enable && !$disable) { + return null; + } + + return $enable === true || !$disable; + } }