Completed
Push — Recipes ( 98dbcc...cc19df )
by Laurent
02:38
created

LoadUserData::setContainer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * LoadUserData Données User de l'application GLSR.
4
 *
5
 * PHP Version 5
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
 * @link      https://github.com/Dev-Int/glsr
14
 */
15
namespace AppBundle\DataFixtures\ORM;
16
17
use Doctrine\Common\DataFixtures\AbstractFixture;
18
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
19
use Doctrine\Common\Persistence\ObjectManager;
20
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
21
use Symfony\Component\DependencyInjection\ContainerInterface;
22
use AppBundle\Entity\Staff\User;
23
use AppBundle\Entity\Staff\Group;
24
25
/**
26
 * LoadUser Data.
27
 *
28
 * @category DataFixtures
29
 */
30
class LoadUserData extends AbstractFixture implements OrderedFixtureInterface, ContainerAwareInterface
31
{
32
    /**
33
     * @var ContainerInterface
34
     */
35
    private $container;
36
37
    public function setContainer(ContainerInterface $container = null)
38
    {
39
        $this->container = $container;
40
    }
41
42
    public function load(ObjectManager $manager)
43
    {
44
        $userAdmin = new User();
45
        $userAdmin->setUsername('Admin');
46
        $userAdmin->setEmail('admin@localhost');
47
        $userAdmin->setEnabled(true);
48
        $userAdmin->setSalt(md5(uniqid()));
49
        
50
        // the 'security.password_encoder' service requires Symfony 2.6 or higher
51
        $encoder = $this->container->get('security.password_encoder');
52
        $password = $encoder->encodePassword($userAdmin, 'admin');
53
        $userAdmin->setPassword($password);
54
55
        $group = new Group('admin', 'ROLE_SUPER_ADMIN');
0 ignored issues
show
Documentation introduced by
'ROLE_SUPER_ADMIN' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
56
        var_dump($group);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($group); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
57
        $userAdmin->setGroups($group->getId(1));
0 ignored issues
show
Unused Code introduced by
The call to Group::getId() has too many arguments starting with 1.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
Documentation introduced by
$group->getId(1) is of type integer, but the function expects a null|object<Doctrine\Com...ctions\ArrayCollection>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
58
59
        $manager->persist($userAdmin);
60
        $manager->flush();
61
62
        $this->addReference('admin-user', $userAdmin);
63
    }
64
65
    public function getOrder()
66
    {
67
        return 2;
68
    }
69
}
70