Completed
Push — Recipes ( c0466a...7632b6 )
by Laurent
04:22
created

LoadUserData::load()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 1
dl 0
loc 15
rs 9.9332
c 0
b 0
f 0
1
<?php
2
/**
3
 * LoadUserData Données User de l'application GLSR.
4
 *
5
 * PHP Version 7
6
 *
7
 * @author    Quétier Laurent <[email protected]>
8
 * @copyright 2018 Dev-Int GLSR
9
 * @license   http://opensource.org/licenses/gpl-license.php GNU Public License
10
 *
11
 * @version GIT: $Id$
12
 *
13
 * @see https://github.com/Dev-Int/glsr
14
 */
15
16
namespace App\DataFixtures\ORM;
17
18
use Doctrine\Common\DataFixtures\AbstractFixture;
19
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
20
use Doctrine\Common\Persistence\ObjectManager;
21
use App\Entity\User;
22
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
23
24
/**
25
 * LoadUser Data.
26
 *
27
 * @category DataFixtures
28
 */
29
class LoadUserData extends AbstractFixture implements OrderedFixtureInterface
30
{
31
    protected $encoder;
32
33
    public function __construct(UserPasswordEncoderInterface $encoder)
34
    {
35
        $this->encoder = $encoder;
36
    }
37
38
    /**
39
     * Load data fixtures with the passed EntityManager.
40
     *
41
     * @param ObjectManager $manager
42
     */
43
    public function load(ObjectManager $manager)
44
    {
45
        $userAdmin = new User();
46
        $userAdmin->setUsername('Admin');
47
        $userAdmin->setEmail('admin@localhost');
0 ignored issues
show
Bug introduced by
The method setEmail() does not exist on App\Entity\User. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

47
        $userAdmin->/** @scrutinizer ignore-call */ 
48
                    setEmail('admin@localhost');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
48
        $userAdmin->setEnabled(true);
49
50
        $password = $this->encoder->encodePassword($userAdmin, 'adminadmin');
51
        $userAdmin->setPassword($password);
52
        $userAdmin->setRoles(['ROLE_SUPER_ADMIN']);
53
54
        $manager->persist($userAdmin);
55
        $manager->flush();
56
57
        $this->addReference('admin-user', $userAdmin);
58
    }
59
60
    /**
61
     * Get the order of this fixture.
62
     *
63
     * @return int
64
     */
65
    public function getOrder()
66
    {
67
        return 1;
68
    }
69
}
70