Completed
Push — Recipes ( 630f49...c8afb0 )
by Laurent
12:15 queued 03:48
created

LoadUserData   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 0
loc 53
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A load() 0 20 1
A getDependencies() 0 4 1
A getGroups() 0 4 1
1
<?php
2
/**
3
 * LoadUserData User data from the GLSR application.
4
 *
5
 * PHP Version 7
6
 *
7
 * @author    Quétier Laurent <[email protected]>
8
 * @copyright 2014 Dev-Int GLSR
9
 * @license   http://opensource.org/licenses/gpl-license.php GNU Public License
10
 *
11
 * @version GIT: <git_id>
12
 *
13
 * @see      https://github.com/Dev-Int/glsr
14
 */
15
16
namespace App\DataFixtures;
17
18
use App\Entity\Staff\User;
19
use Doctrine\Common\Persistence\ObjectManager;
20
use Doctrine\Bundle\FixturesBundle\Fixture;
21
use Doctrine\Common\Collections\ArrayCollection;
22
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
23
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
24
use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface;
25
26
/**
27
 * LoadUser Data.
28
 *
29
 * @category DataFixtures
30
 */
31
class LoadUserData extends Fixture implements DependentFixtureInterface, FixtureGroupInterface
32
{
33
    /**
34
     * Encoder.
35
     *
36
     * @var UserPasswordEncoderInterface
37
     */
38
    protected $encoder;
39
40
    public function __construct(UserPasswordEncoderInterface $encoder)
41
    {
42
        $this->encoder = $encoder;
43
    }
44
45
    /**
46
     * Load data fixtures with the passed EntityManager.
47
     *
48
     * @param ObjectManager $manager
49
     */
50
    public function load(ObjectManager $manager)
51
    {
52
        $userAdmin = new User();
53
        $userAdmin->setUsername('Admin');
54
        $userAdmin->setEmail('admin@localhost');
55
        $userAdmin->setEnabled(true);
56
        $userAdmin->setSalt(md5(uniqid()));
57
58
        $password = $this->encoder->encodePassword($userAdmin, 'admin');
59
        $userAdmin->setPassword($password);
60
        $userAdmin->setRoles(['ROLE_SUPER_ADMIN']);
61
62
        $group = new ArrayCollection([$this->getReference('group-admin')]);
63
        $userAdmin->setGroups($group);
64
65
        $manager->persist($userAdmin);
66
        $manager->flush();
67
68
        $this->addReference('user-Admin', $userAdmin);
69
    }
70
71
    /**
72
     * Get the dependencies.
73
     */
74
    public function getDependencies()
75
    {
76
        return [LoadGroupData::class];
77
    }
78
79
    public static function getGroups(): array
80
    {
81
        return ['userGroup'];
82
    }
83
}
84