Completed
Push — master ( b2cd25...08acda )
by Paweł
26s queued 10s
created

UserFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 20
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 8 1
A __construct() 0 4 1
1
<?php
2
3
namespace App\Factory;
4
5
use App\Entity\User;
6
use App\Generator\StringGeneratorInterface;
7
use App\Model\UserInterface;
8
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
9
10
class UserFactory implements UserFactoryInterface
11
{
12
    private $passwordEncoder;
13
14
    protected $stringGenerator;
15
16
    public function __construct(UserPasswordEncoderInterface $passwordEncoder, StringGeneratorInterface $stringGenerator)
17
    {
18
        $this->passwordEncoder = $passwordEncoder;
19
        $this->stringGenerator = $stringGenerator;
20
    }
21
22
    public function create(): UserInterface
23
    {
24
        $user = new User();
25
        $generatedPassword = $this->passwordEncoder->encodePassword($user, $this->stringGenerator::random(7));
26
        $user->setPassword($generatedPassword);
27
        $user->setPasswordNeedToBeChanged(true);
28
29
        return $user;
30
    }
31
}
32