Completed
Push — master ( 402c8e...a49823 )
by Philip
22:11
created

Users   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 0
cbo 5
dl 0
loc 65
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setContainer() 0 4 1
B load() 0 42 1
1
<?php
2
3
namespace App\DataFixtures;
4
5
use App\Entity\User;
6
use Doctrine\Common\DataFixtures\AbstractFixture;
7
use Doctrine\Common\Persistence\ObjectManager;
8
use FOS\UserBundle\Model\UserManagerInterface;
9
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
10
use Symfony\Component\DependencyInjection\ContainerInterface;
11
12
class Users extends AbstractFixture implements ContainerAwareInterface
13
{
14
    const WATCHER = 'user_watcher';
15
    const COMMITTER = 'user_committer';
16
    const ADMIN = 'user_admin';
17
18
    /**
19
     * @var ContainerInterface
20
     */
21
    private $container;
22
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function setContainer(ContainerInterface $container = null)
27
    {
28
        $this->container = $container;
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function load(ObjectManager $manager)
35
    {
36
        /** @var UserManagerInterface $userManager */
37
        $userManager = $this->container->get('fos_user.user_manager');
38
39
        /** @var User $user */
40
        $user = $userManager->createUser();
41
        $user->setUsername('watcher');
42
        $user->setRealName('Watcher User');
43
        $user->setEmail('[email protected]');
44
        $user->setPlainPassword('watcher');
45
        $user->addRole('ROLE_WATCHER');
46
        $user->setEnabled(true);
47
48
        $userManager->updateUser($user);
49
        $this->addReference(self::WATCHER, $user);
50
51
        $user = $userManager->createUser();
52
        $user->setUsername('committer');
53
        $user->setRealName('Committer User');
54
        $user->setEmail('[email protected]');
55
        $user->setPlainPassword('committer');
56
        $user->addRole('ROLE_WATCHER');
57
        $user->addRole('ROLE_COMMITTER');
58
        $user->setEnabled(true);
59
60
        $userManager->updateUser($user);
61
        $this->addReference(self::COMMITTER, $user);
62
63
        $user = $userManager->createUser();
64
        $user->setUsername('admin');
65
        $user->setRealName('Admin User');
66
        $user->setEmail('[email protected]');
67
        $user->setPlainPassword('admin');
68
        $user->addRole('ROLE_WATCHER');
69
        $user->addRole('ROLE_COMMITTER');
70
        $user->addRole('ROLE_ADMIN');
71
        $user->setEnabled(true);
72
73
        $userManager->updateUser($user);
74
        $this->addReference(self::ADMIN, $user);
75
    }
76
}
77