Completed
Push — master ( cf207c...9dbd6f )
by Valery
08:47
created

UserFixtures::getUserData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\DataFixtures;
6
7
use App\Entity\User;
8
use Doctrine\Bundle\FixturesBundle\Fixture;
9
use Doctrine\Persistence\ObjectManager;
10
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
11
12
final class UserFixtures extends Fixture
13
{
14
    /**
15
     * @var UserPasswordEncoderInterface
16
     */
17
    private $passwordEncoder;
18
19
    public function __construct(UserPasswordEncoderInterface $passwordEncoder)
20
    {
21
        $this->passwordEncoder = $passwordEncoder;
22
    }
23
24
    public function load(ObjectManager $manager): void
25
    {
26
        foreach ($this->getUserData() as [$fullName, $username, $phone, $email, $roles]) {
27
            $user = new User();
28
            $user->setFullName($fullName);
0 ignored issues
show
Bug introduced by
The variable $fullName does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
29
            $user->setUsername($username);
0 ignored issues
show
Bug introduced by
The variable $username does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
30
            $user->setPassword($this->passwordEncoder->encodePassword(
31
                $user, $username
32
            ));
33
            $user->setPhone($phone);
0 ignored issues
show
Bug introduced by
The variable $phone does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
34
            $user->setEmail($email);
0 ignored issues
show
Bug introduced by
The variable $email does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
35
            $user->setRoles($roles);
0 ignored issues
show
Bug introduced by
The variable $roles does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
36
            $manager->persist($user);
37
            $this->addReference($username, $user);
38
        }
39
        $manager->flush();
40
    }
41
42
    private function getUserData(): array
43
    {
44
        return [
45
            // $cityData = [$fullName, $username, $phone, $email, $roles];
46
            ['John Smith', 'admin', '0(0)99766899', '[email protected]', ['ROLE_ADMIN', 'ROLE_USER']],
47
            ['Rhonda Jordan', 'user', '0(0)99766899', '[email protected]', ['ROLE_USER']],
48
        ];
49
    }
50
}
51