remove password generation from the user factory

This commit is contained in:
Simon Vieille 2022-02-28 09:35:54 +01:00
parent ded0279514
commit e81f8be151

View file

@ -16,9 +16,8 @@ class UserFactory implements FactoryInterface
protected TokenGeneratorInterface $tokenGenerator; protected TokenGeneratorInterface $tokenGenerator;
protected UserPasswordEncoderInterface $encoder; protected UserPasswordEncoderInterface $encoder;
public function __construct(TokenGeneratorInterface $tokenGenerator, UserPasswordEncoderInterface $encoder) public function __construct(UserPasswordEncoderInterface $encoder)
{ {
$this->tokenGenerator = $tokenGenerator;
$this->encoder = $encoder; $this->encoder = $encoder;
} }
@ -26,14 +25,13 @@ class UserFactory implements FactoryInterface
{ {
$entity = new User(); $entity = new User();
if (!empty($email)) { if (null !== $email) {
$entity->setEmail($email); $entity->setEmail($email);
} }
$entity->setPassword($this->encoder->encodePassword( if (null !== $email) {
$entity, $entity->setPassword($this->encoder->encodePassword($entity, $password));
!empty($password) ? $password : $this->tokenGenerator->generateToken() }
));
return $entity; return $entity;
} }