Skip to content

Commit

Permalink
Merge pull request #3069 from stof/return_types
Browse files Browse the repository at this point in the history
Add return types in all methods
  • Loading branch information
stof authored Jan 16, 2024
2 parents 8ccde38 + 62eaceb commit 4c0a2a8
Show file tree
Hide file tree
Showing 14 changed files with 106 additions and 13 deletions.
6 changes: 3 additions & 3 deletions Doctrine/CouchDB/UserListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ public function getSubscribedEvents(): array
];
}

public function prePersist(LifecycleEventArgs $args)
public function prePersist(LifecycleEventArgs $args): void
{
$object = $args->getDocument();
if ($object instanceof UserInterface) {
$this->updateUserFields($object);
}
}

public function preUpdate(LifecycleEventArgs $args)
public function preUpdate(LifecycleEventArgs $args): void
{
$object = $args->getDocument();
if ($object instanceof UserInterface) {
Expand All @@ -61,7 +61,7 @@ public function preUpdate(LifecycleEventArgs $args)
/**
* Updates the user properties.
*/
private function updateUserFields(UserInterface $user)
private function updateUserFields(UserInterface $user): void
{
$this->canonicalFieldsUpdater->updateCanonicalFields($user);
$this->passwordUpdater->hashPassword($user);
Expand Down
8 changes: 4 additions & 4 deletions Doctrine/UserListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function getSubscribedEvents(): array
/**
* Pre persist listener based on doctrine common.
*/
public function prePersist(LifecycleEventArgs $args)
public function prePersist(LifecycleEventArgs $args): void
{
$object = $args->getObject();
if ($object instanceof UserInterface) {
Expand All @@ -63,7 +63,7 @@ public function prePersist(LifecycleEventArgs $args)
/**
* Pre update listener based on doctrine common.
*/
public function preUpdate(LifecycleEventArgs $args)
public function preUpdate(LifecycleEventArgs $args): void
{
$object = $args->getObject();
if ($object instanceof UserInterface) {
Expand All @@ -75,7 +75,7 @@ public function preUpdate(LifecycleEventArgs $args)
/**
* Updates the user properties.
*/
private function updateUserFields(UserInterface $user)
private function updateUserFields(UserInterface $user): void
{
$this->canonicalFieldsUpdater->updateCanonicalFields($user);
$this->passwordUpdater->hashPassword($user);
Expand All @@ -84,7 +84,7 @@ private function updateUserFields(UserInterface $user)
/**
* Recomputes change set for Doctrine implementations not doing it automatically after the event.
*/
private function recomputeChangeSet(ObjectManager $om, UserInterface $user)
private function recomputeChangeSet(ObjectManager $om, UserInterface $user): void
{
$meta = $om->getClassMetadata(get_class($user));

Expand Down
22 changes: 21 additions & 1 deletion Doctrine/UserManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,20 @@ public function __construct(PasswordUpdaterInterface $passwordUpdater, Canonical
$this->class = $class;
}

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

/**
* @return string
*
* @phpstan-return class-string<UserInterface>
*/
public function getClass()
{
if (false !== strpos($this->class, ':')) {
Expand All @@ -59,21 +67,33 @@ public function getClass()
return $this->class;
}

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

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

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

/**
* @return void
*/
public function updateUser(UserInterface $user, $andFlush = true)
{
$this->updateCanonicalFields($user);
Expand All @@ -86,7 +106,7 @@ public function updateUser(UserInterface $user, $andFlush = true)
}

/**
* @return ObjectRepository
* @return ObjectRepository<UserInterface>
*/
protected function getRepository()
{
Expand Down
10 changes: 7 additions & 3 deletions Form/Factory/FormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace FOS\UserBundle\Form\Factory;

use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormInterface;

class FormFactory implements FactoryInterface
{
Expand All @@ -38,9 +39,9 @@ class FormFactory implements FactoryInterface
/**
* FormFactory constructor.
*
* @param string $name
* @param string $type
* @param array $validationGroups
* @param string $name
* @param string $type
* @param string[]|null $validationGroups
*/
public function __construct(FormFactoryInterface $formFactory, $name, $type, array $validationGroups = null)
{
Expand All @@ -50,6 +51,9 @@ public function __construct(FormFactoryInterface $formFactory, $name, $type, arr
$this->validationGroups = $validationGroups;
}

/**
* @return FormInterface
*/
public function createForm(array $options = [])
{
$options = array_merge(['validation_groups' => $this->validationGroups], $options);
Expand Down
4 changes: 4 additions & 0 deletions Mailer/MailerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@ interface MailerInterface
{
/**
* Send an email to a user to confirm the account creation.
*
* @return void
*/
public function sendConfirmationEmailMessage(UserInterface $user);

/**
* Send an email to a user to confirm the password reset.
*
* @return void
*/
public function sendResettingEmailMessage(UserInterface $user);
}
6 changes: 6 additions & 0 deletions Mailer/NoopMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,17 @@
*/
class NoopMailer implements MailerInterface
{
/**
* @return void
*/
public function sendConfirmationEmailMessage(UserInterface $user)
{
// nothing happens.
}

/**
* @return void
*/
public function sendResettingEmailMessage(UserInterface $user)
{
// nothing happens.
Expand Down
8 changes: 8 additions & 0 deletions Mailer/TwigSwiftMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public function __construct(\Swift_Mailer $mailer, UrlGeneratorInterface $router
$this->parameters = $parameters;
}

/**
* @return void
*/
public function sendConfirmationEmailMessage(UserInterface $user)
{
$template = $this->parameters['template']['confirmation'];
Expand All @@ -61,6 +64,9 @@ public function sendConfirmationEmailMessage(UserInterface $user)
$this->sendMessage($template, $context, $this->parameters['from_email']['confirmation'], (string) $user->getEmail());
}

/**
* @return void
*/
public function sendResettingEmailMessage(UserInterface $user)
{
$template = $this->parameters['template']['resetting'];
Expand All @@ -79,6 +85,8 @@ public function sendResettingEmailMessage(UserInterface $user)
* @param array $context
* @param array $fromEmail
* @param string $toEmail
*
* @return void
*/
protected function sendMessage($templateName, $context, $fromEmail, $toEmail)
{
Expand Down
21 changes: 21 additions & 0 deletions Model/UserManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public function __construct(PasswordUpdaterInterface $passwordUpdater, Canonical
$this->canonicalFieldsUpdater = $canonicalFieldsUpdater;
}

/**
* @return UserInterface
*/
public function createUser()
{
$class = $this->getClass();
Expand All @@ -39,16 +42,25 @@ public function createUser()
return $user;
}

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

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

/**
* @return UserInterface|null
*/
public function findUserByUsernameOrEmail($usernameOrEmail)
{
if (preg_match('/^.+\@\S+\.\S+$/', $usernameOrEmail)) {
Expand All @@ -61,16 +73,25 @@ public function findUserByUsernameOrEmail($usernameOrEmail)
return $this->findUserByUsername($usernameOrEmail);
}

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

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

/**
* @return void
*/
public function updatePassword(UserInterface $user)
{
$this->passwordUpdater->hashPassword($user);
Expand Down
14 changes: 13 additions & 1 deletion Model/UserManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public function createUser();

/**
* Deletes a user.
*
* @return void
*/
public function deleteUser(UserInterface $user);

Expand Down Expand Up @@ -84,34 +86,44 @@ public function findUserByConfirmationToken($token);
/**
* Returns a collection with all user instances.
*
* @return \Traversable
* @return \Traversable<UserInterface>
*/
public function findUsers();

/**
* Returns the user's fully qualified class name.
*
* @return string
*
* @phpstan-return class-string<UserInterface>
*/
public function getClass();

/**
* Reloads a user.
*
* @return void
*/
public function reloadUser(UserInterface $user);

/**
* Updates a user.
*
* @return void
*/
public function updateUser(UserInterface $user);

/**
* Updates the canonical username and email fields for a user.
*
* @return void
*/
public function updateCanonicalFields(UserInterface $user);

/**
* Updates a user password if a plain password is set.
*
* @return void
*/
public function updatePassword(UserInterface $user);
}
2 changes: 1 addition & 1 deletion Security/LoginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function __construct(TokenStorageInterface $tokenStorage, UserCheckerInte
$this->rememberMeHandler = $rememberMeHandler;
}

final public function logInUser($firewallName, UserInterface $user, Response $response = null)
final public function logInUser($firewallName, UserInterface $user, Response $response = null): void
{
$this->userChecker->checkPreAuth($user);

Expand Down
2 changes: 2 additions & 0 deletions Security/LoginManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ interface LoginManagerInterface
{
/**
* @param string $firewallName
*
* @return void
*/
public function logInUser($firewallName, UserInterface $user, Response $response = null);
}
3 changes: 3 additions & 0 deletions Util/HashingPasswordUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public function __construct(PasswordHasherFactoryInterface $passwordHasherFactor
$this->passwordHasherFactory = $passwordHasherFactory;
}

/**
* @return void
*/
public function hashPassword(UserInterface $user)
{
$plainPassword = $user->getPlainPassword();
Expand Down
3 changes: 3 additions & 0 deletions Util/PasswordUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public function __construct(EncoderFactoryInterface $encoderFactory)
$this->encoderFactory = $encoderFactory;
}

/**
* @return void
*/
public function hashPassword(UserInterface $user)
{
$plainPassword = $user->getPlainPassword();
Expand Down
Loading

0 comments on commit 4c0a2a8

Please sign in to comment.