Skip to content

Commit

Permalink
Fix SA (#1694)
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet authored Aug 26, 2024
1 parent 8713dce commit a293f40
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/Action/ResetAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __invoke(Request $request, string $token): Response
$user = $this->userManager->findUserByConfirmationToken($token);

if (null === $user) {
throw new NotFoundHttpException(sprintf('The user with "confirmation token" does not exist for value "%s"', $token));
throw new NotFoundHttpException(\sprintf('The user with "confirmation token" does not exist for value "%s"', $token));
}

if (!$user->isPasswordRequestNonExpired($this->tokenTtl)) {
Expand Down
4 changes: 2 additions & 2 deletions src/Command/ActivateUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$user = $this->userManager->findUserByUsername($username);

if (null === $user) {
throw new \InvalidArgumentException(sprintf('User identified by "%s" username does not exist.', $username));
throw new \InvalidArgumentException(\sprintf('User identified by "%s" username does not exist.', $username));
}

$user->setEnabled(true);

$this->userManager->save($user);

$output->writeln(sprintf('User "%s" has been activated.', $username));
$output->writeln(\sprintf('User "%s" has been activated.', $username));

return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Command/ChangePasswordCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$user = $this->userManager->findUserByUsername($username);

if (null === $user) {
throw new \InvalidArgumentException(sprintf('User identified by "%s" username does not exist.', $username));
throw new \InvalidArgumentException(\sprintf('User identified by "%s" username does not exist.', $username));
}

$user->setPlainPassword($password);

$this->userManager->updatePassword($user);
$this->userManager->save($user);

$output->writeln(sprintf('Changed password for user "%s".', $username));
$output->writeln(\sprintf('Changed password for user "%s".', $username));

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Command/CreateUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$this->userManager->save($user);

$output->writeln(sprintf('Created user "%s".', $username));
$output->writeln(\sprintf('Created user "%s".', $username));

return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Command/DeactivateUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$user = $this->userManager->findUserByUsername($username);

if (null === $user) {
throw new \InvalidArgumentException(sprintf('User identified by "%s" username does not exist.', $username));
throw new \InvalidArgumentException(\sprintf('User identified by "%s" username does not exist.', $username));
}

$user->setEnabled(false);

$this->userManager->save($user);

$output->writeln(sprintf('User "%s" has been activated.', $username));
$output->writeln(\sprintf('User "%s" has been activated.', $username));

return 0;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Command/DemoteUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$user = $this->userManager->findUserByUsername($username);

if (null === $user) {
throw new \InvalidArgumentException(sprintf('User identified by "%s" username does not exist.', $username));
throw new \InvalidArgumentException(\sprintf('User identified by "%s" username does not exist.', $username));
}

if ($superAdmin) {
$user->setSuperAdmin(false);

$output->writeln(sprintf('User "%s" has been demoted as a simple user. This change will not apply until the user logs out and back in again.', $username));
$output->writeln(\sprintf('User "%s" has been demoted as a simple user. This change will not apply until the user logs out and back in again.', $username));
} elseif ($user->hasRole($role)) {
$user->removeRole($role);

$output->writeln(sprintf('Role "%s" has been removed from user "%s". This change will not apply until the user logs out and back in again.', $role, $username));
$output->writeln(\sprintf('Role "%s" has been removed from user "%s". This change will not apply until the user logs out and back in again.', $role, $username));
} else {
$output->writeln(sprintf('User "%s" didn\'t have "%s" role.', $username, $role));
$output->writeln(\sprintf('User "%s" didn\'t have "%s" role.', $username, $role));
}

$this->userManager->save($user);
Expand Down
8 changes: 4 additions & 4 deletions src/Command/PromoteUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$user = $this->userManager->findUserByUsername($username);

if (null === $user) {
throw new \InvalidArgumentException(sprintf('User identified by "%s" username does not exist.', $username));
throw new \InvalidArgumentException(\sprintf('User identified by "%s" username does not exist.', $username));
}

if ($superAdmin) {
$user->setSuperAdmin(true);

$output->writeln(sprintf('User "%s" has been promoted as a super administrator. This change will not apply until the user logs out and back in again.', $username));
$output->writeln(\sprintf('User "%s" has been promoted as a super administrator. This change will not apply until the user logs out and back in again.', $username));
} elseif (!$user->hasRole($role)) {
$user->addRole($role);

$output->writeln(sprintf('Role "%s" has been added to user "%s". This change will not apply until the user logs out and back in again.', $role, $username));
$output->writeln(\sprintf('Role "%s" has been added to user "%s". This change will not apply until the user logs out and back in again.', $role, $username));
} else {
$output->writeln(sprintf('User "%s" did already have "%s" role.', $username, $role));
$output->writeln(\sprintf('User "%s" did already have "%s" role.', $username, $role));
}

$this->userManager->save($user);
Expand Down
8 changes: 4 additions & 4 deletions src/DependencyInjection/SonataUserExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ public function load(array $configs, ContainerBuilder $container): void

if (isset($bundles['SonataAdminBundle'])) {
$loader->load('admin.php');
$loader->load(sprintf('admin_%s.php', $config['manager_type']));
$loader->load(\sprintf('admin_%s.php', $config['manager_type']));
$loader->load('actions.php');
}

$loader->load(sprintf('%s.php', $config['manager_type']));
$loader->load(\sprintf('%s.php', $config['manager_type']));
$container->setParameter('sonata.user.manager_type', $config['manager_type']);

$loader->load('twig.php');
Expand Down Expand Up @@ -139,7 +139,7 @@ private function checkManagerTypeToModelTypesMapping(array $config): void
$managerType = $config['manager_type'];

if (!\in_array($managerType, ['orm', 'mongodb'], true)) {
throw new \InvalidArgumentException(sprintf('Invalid manager type "%s".', $managerType));
throw new \InvalidArgumentException(\sprintf('Invalid manager type "%s".', $managerType));
}

$this->prohibitModelTypeMapping(
Expand All @@ -162,7 +162,7 @@ private function prohibitModelTypeMapping(
): void {
if (is_a($actualModelClass, $prohibitedModelClass, true)) {
throw new \InvalidArgumentException(
sprintf(
\sprintf(
'Model class "%s" does not correspond to manager type "%s".',
$actualModelClass,
$managerType
Expand Down
2 changes: 1 addition & 1 deletion src/Mailer/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function sendResettingEmailMessage(UserInterface $user): void

$this->mailer->send(
(new Email())
->from(sprintf('%s <%s>', $fromName, $fromAddress))
->from(\sprintf('%s <%s>', $fromName, $fromAddress))
->to((string) $user->getEmail())
->subject($subject)
->html($body)
Expand Down
2 changes: 1 addition & 1 deletion src/Security/RolesBuilder/AdminRolesBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private function getAdminRolesByAdminCode(string $code, ?string $domain = null,
$adminLabelTranslated = $admin->getTranslator()->trans($admin->getLabel() ?? '', [], $admin->getTranslationDomain());
$isMasterAdmin = $this->isMaster($admin);
foreach (array_keys($admin->getSecurityInformation()) as $key) {
$role = sprintf($baseRole, $key);
$role = \sprintf($baseRole, $key);
$adminRoles[$role] = [
'role' => $role,
'label' => $key,
Expand Down
8 changes: 4 additions & 4 deletions src/Security/UserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function loadUserByIdentifier(string $identifier): SecurityUserInterface
$user = $this->findUser($identifier);

if (null === $user || !$user->isEnabled()) {
throw new UserNotFoundException(sprintf('Username "%s" does not exist.', $identifier));
throw new UserNotFoundException(\sprintf('Username "%s" does not exist.', $identifier));
}

return $user;
Expand All @@ -51,15 +51,15 @@ public function loadUserByIdentifier(string $identifier): SecurityUserInterface
public function refreshUser(SecurityUserInterface $user): SecurityUserInterface
{
if (!$user instanceof UserInterface) {
throw new UnsupportedUserException(sprintf('Expected an instance of %s, but got "%s".', UserInterface::class, $user::class));
throw new UnsupportedUserException(\sprintf('Expected an instance of %s, but got "%s".', UserInterface::class, $user::class));
}

if (!$this->supportsClass($user::class)) {
throw new UnsupportedUserException(sprintf('Expected an instance of %s, but got "%s".', $this->userManager->getClass(), $user::class));
throw new UnsupportedUserException(\sprintf('Expected an instance of %s, but got "%s".', $this->userManager->getClass(), $user::class));
}

if (null === $reloadedUser = $this->userManager->findOneBy(['id' => $user->getId()])) {
throw new UserNotFoundException(sprintf('User with ID "%s" could not be reloaded.', $user->getId() ?? ''));
throw new UserNotFoundException(\sprintf('User with ID "%s" could not be reloaded.', $user->getId() ?? ''));
}

return $reloadedUser;
Expand Down
4 changes: 2 additions & 2 deletions tests/Functional/Action/ResetActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testItSubmitsResetPasswordFormWithNonValidData(): void

static::assertSame($user->getPassword(), 'random_password');

$client->request('GET', sprintf('/reset/%s', $confirmationToken));
$client->request('GET', \sprintf('/reset/%s', $confirmationToken));

static::assertResponseIsSuccessful();

Expand All @@ -62,7 +62,7 @@ public function testItResetsPassword(): void

static::assertSame($user->getPassword(), 'random_password');

$client->request('GET', sprintf('/reset/%s', $confirmationToken));
$client->request('GET', \sprintf('/reset/%s', $confirmationToken));

$client->submitForm('submit', [
'resetting_form[plainPassword][first]' => 'new_password',
Expand Down
2 changes: 1 addition & 1 deletion tests/Mailer/MailerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function testSendResettingEmailMessage(string $template, string $subject,
$fromAddress = current(array_keys($this->emailFrom));

$email = (new Email())
->from(sprintf('%s <%s>', $fromName, $fromAddress))
->from(\sprintf('%s <%s>', $fromName, $fromAddress))
->to((string) $user->getEmail())
->subject($subject)
->html($body);
Expand Down

0 comments on commit a293f40

Please sign in to comment.