Skip to content

Commit

Permalink
Merge pull request #3080 from stof/return_types
Browse files Browse the repository at this point in the history
Add native return types
  • Loading branch information
stof authored Jun 25, 2024
2 parents 49f2c44 + fd22eae commit dc09a0c
Show file tree
Hide file tree
Showing 41 changed files with 82 additions and 260 deletions.
10 changes: 2 additions & 8 deletions src/Controller/SecurityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,12 @@ public function loginAction(): Response
]);
}

/**
* @return never
*/
public function checkAction()
public function checkAction(): never
{
throw new \RuntimeException('You must configure the check path to be handled by the firewall using form_login in your security firewall configuration.');
}

/**
* @return never
*/
public function logoutAction()
public function logoutAction(): never
{
throw new \RuntimeException('You must activate the logout in your security firewall configuration.');
}
Expand Down
28 changes: 7 additions & 21 deletions src/Doctrine/UserManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,16 @@ public function __construct(PasswordUpdaterInterface $passwordUpdater, Canonical
$this->class = $class;
}

/**
* @return void
*/
public function deleteUser(UserInterface $user)
public function deleteUser(UserInterface $user): void
{
$this->objectManager->remove($user);
$this->objectManager->flush();
}

/**
* @return string
*
* @phpstan-return class-string<UserInterface>
*/
public function getClass()
public function getClass(): string
{
if (false !== strpos($this->class, ':')) {
$metadata = $this->objectManager->getClassMetadata($this->class);
Expand All @@ -67,34 +62,25 @@ public function getClass()
return $this->class;
}

/**
* @return UserInterface|null
*/
public function findUserBy(array $criteria)
public function findUserBy(array $criteria): ?UserInterface
{
return $this->getRepository()->findOneBy($criteria);
}

/**
* @return iterable<UserInterface>
*/
public function findUsers()
public function findUsers(): iterable
{
return $this->getRepository()->findAll();
}

/**
* @return void
*/
public function reloadUser(UserInterface $user)
public function reloadUser(UserInterface $user): void
{
$this->objectManager->refresh($user);
}

/**
* @return void
*/
public function updateUser(UserInterface $user, $andFlush = true)
public function updateUser(UserInterface $user, $andFlush = true): void
{
$this->updateCanonicalFields($user);
$this->updatePassword($user);
Expand All @@ -108,7 +94,7 @@ public function updateUser(UserInterface $user, $andFlush = true)
/**
* @return ObjectRepository<UserInterface>
*/
protected function getRepository()
protected function getRepository(): ObjectRepository
{
return $this->objectManager->getRepository($this->getClass());
}
Expand Down
4 changes: 1 addition & 3 deletions src/Event/FilterUserResponseEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ public function getResponse(): Response

/**
* Sets a new response object.
*
* @return void
*/
public function setResponse(Response $response)
public function setResponse(Response $response): void
{
$this->response = $response;
}
Expand Down
5 changes: 1 addition & 4 deletions src/Event/FormEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ public function getRequest(): Request
return $this->request;
}

/**
* @return void
*/
public function setResponse(Response $response)
public function setResponse(Response $response): void
{
$this->response = $response;
}
Expand Down
5 changes: 1 addition & 4 deletions src/Event/GetResponseNullableUserEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ public function getRequest(): Request
return $this->request;
}

/**
* @return void
*/
public function setResponse(Response $response)
public function setResponse(Response $response): void
{
$this->response = $response;
}
Expand Down
5 changes: 1 addition & 4 deletions src/Event/GetResponseUserEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ final class GetResponseUserEvent extends UserEvent
*/
private $response;

/**
* @return void
*/
public function setResponse(Response $response)
public function setResponse(Response $response): void
{
$this->response = $response;
}
Expand Down
4 changes: 1 addition & 3 deletions src/EventListener/AuthenticationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@ public static function getSubscribedEvents(): array

/**
* @param string $eventName
*
* @return void
*/
public function authenticate(FilterUserResponseEvent $event, $eventName, EventDispatcherInterface $eventDispatcher)
public function authenticate(FilterUserResponseEvent $event, $eventName, EventDispatcherInterface $eventDispatcher): void
{
try {
$this->loginManager->logInUser($this->firewallName, $event->getUser(), $event->getResponse());
Expand Down
5 changes: 1 addition & 4 deletions src/EventListener/EmailConfirmationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ public static function getSubscribedEvents(): array
];
}

/**
* @return void
*/
public function onRegistrationSuccess(FormEvent $event)
public function onRegistrationSuccess(FormEvent $event): void
{
/** @var \FOS\UserBundle\Model\UserInterface $user */
$user = $event->getForm()->getData();
Expand Down
4 changes: 1 addition & 3 deletions src/EventListener/FlashListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,8 @@ public static function getSubscribedEvents(): array

/**
* @param string $eventName
*
* @return void
*/
public function addSuccessFlash(Event $event, $eventName)
public function addSuccessFlash(Event $event, $eventName): void
{
if (!isset(self::$successMessages[$eventName])) {
throw new \InvalidArgumentException('This event does not correspond to a known flash message');
Expand Down
10 changes: 2 additions & 8 deletions src/EventListener/LastLoginListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,15 @@ public static function getSubscribedEvents(): array
];
}

/**
* @return void
*/
public function onImplicitLogin(UserEvent $event)
public function onImplicitLogin(UserEvent $event): void
{
$user = $event->getUser();

$user->setLastLogin(new \DateTime());
$this->userManager->updateUser($user);
}

/**
* @return void
*/
public function onSecurityInteractiveLogin(InteractiveLoginEvent $event)
public function onSecurityInteractiveLogin(InteractiveLoginEvent $event): void
{
$user = $event->getAuthenticationToken()->getUser();

Expand Down
10 changes: 2 additions & 8 deletions src/EventListener/ResettingListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,14 @@ public static function getSubscribedEvents(): array
];
}

/**
* @return void
*/
public function onResettingResetInitialize(GetResponseUserEvent $event)
public function onResettingResetInitialize(GetResponseUserEvent $event): void
{
if (!$event->getUser()->isPasswordRequestNonExpired($this->tokenTtl)) {
$event->setResponse(new RedirectResponse($this->router->generate('fos_user_resetting_request')));
}
}

/**
* @return void
*/
public function onResettingResetSuccess(FormEvent $event)
public function onResettingResetSuccess(FormEvent $event): void
{
/** @var \FOS\UserBundle\Model\UserInterface $user */
$user = $event->getForm()->getData();
Expand Down
5 changes: 1 addition & 4 deletions src/Form/Factory/FactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,5 @@

interface FactoryInterface
{
/**
* @return FormInterface
*/
public function createForm();
public function createForm(): FormInterface;
}
4 changes: 1 addition & 3 deletions src/Form/Factory/FormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,8 @@ public function __construct(FormFactoryInterface $formFactory, $name, $type, ?ar

/**
* @param array<string, mixed> $options
*
* @return FormInterface
*/
public function createForm(array $options = [])
public function createForm(array $options = []): FormInterface
{
$options = array_merge(['validation_groups' => $this->validationGroups], $options);

Expand Down
8 changes: 2 additions & 6 deletions src/Mailer/MailerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,11 @@ interface MailerInterface
{
/**
* Send an email to a user to confirm the account creation.
*
* @return void
*/
public function sendConfirmationEmailMessage(UserInterface $user);
public function sendConfirmationEmailMessage(UserInterface $user): void;

/**
* Send an email to a user to confirm the password reset.
*
* @return void
*/
public function sendResettingEmailMessage(UserInterface $user);
public function sendResettingEmailMessage(UserInterface $user): void;
}
10 changes: 2 additions & 8 deletions src/Mailer/NoopMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,12 @@
*/
final class NoopMailer implements MailerInterface
{
/**
* @return void
*/
public function sendConfirmationEmailMessage(UserInterface $user)
public function sendConfirmationEmailMessage(UserInterface $user): void
{
// nothing happens.
}

/**
* @return void
*/
public function sendResettingEmailMessage(UserInterface $user)
public function sendResettingEmailMessage(UserInterface $user): void
{
// nothing happens.
}
Expand Down
45 changes: 9 additions & 36 deletions src/Model/UserManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,37 +31,25 @@ public function __construct(PasswordUpdaterInterface $passwordUpdater, Canonical
$this->canonicalFieldsUpdater = $canonicalFieldsUpdater;
}

/**
* @return UserInterface
*/
public function createUser()
public function createUser(): UserInterface
{
$class = $this->getClass();
$user = new $class();

return $user;
}

/**
* @return UserInterface|null
*/
public function findUserByEmail($email)
public function findUserByEmail($email): ?UserInterface
{
return $this->findUserBy(['emailCanonical' => $this->canonicalFieldsUpdater->canonicalizeEmail($email)]);
}

/**
* @return UserInterface|null
*/
public function findUserByUsername($username)
public function findUserByUsername($username): ?UserInterface
{
return $this->findUserBy(['usernameCanonical' => $this->canonicalFieldsUpdater->canonicalizeUsername($username)]);
}

/**
* @return UserInterface|null
*/
public function findUserByUsernameOrEmail($usernameOrEmail)
public function findUserByUsernameOrEmail($usernameOrEmail): ?UserInterface
{
if (preg_match('/^.+\@\S+\.\S+$/', $usernameOrEmail)) {
$user = $this->findUserByEmail($usernameOrEmail);
Expand All @@ -73,42 +61,27 @@ public function findUserByUsernameOrEmail($usernameOrEmail)
return $this->findUserByUsername($usernameOrEmail);
}

/**
* @return UserInterface|null
*/
public function findUserByConfirmationToken($token)
public function findUserByConfirmationToken($token): ?UserInterface
{
return $this->findUserBy(['confirmationToken' => $token]);
}

/**
* @return void
*/
public function updateCanonicalFields(UserInterface $user)
public function updateCanonicalFields(UserInterface $user): void
{
$this->canonicalFieldsUpdater->updateCanonicalFields($user);
}

/**
* @return void
*/
public function updatePassword(UserInterface $user)
public function updatePassword(UserInterface $user): void
{
$this->passwordUpdater->hashPassword($user);
}

/**
* @return PasswordUpdaterInterface
*/
protected function getPasswordUpdater()
protected function getPasswordUpdater(): PasswordUpdaterInterface
{
return $this->passwordUpdater;
}

/**
* @return CanonicalFieldsUpdater
*/
protected function getCanonicalFieldsUpdater()
protected function getCanonicalFieldsUpdater(): CanonicalFieldsUpdater
{
return $this->canonicalFieldsUpdater;
}
Expand Down
Loading

0 comments on commit dc09a0c

Please sign in to comment.