LoadUserData::addTestUser()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 11

Duplication

Lines 17
Ratio 100 %

Code Coverage

Tests 12
CRAP Score 1

Importance

Changes 0
Metric Value
dl 17
loc 17
ccs 12
cts 12
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 11
nc 1
nop 1
crap 1
1
<?php
2
3
/**
4
 * This file is part of Webcook security bundle.
5
 *
6
 * See LICENSE file in the root of the bundle. Webcook 
7
 */
8
9
namespace Webcook\Cms\SecurityBundle\DataFixtures\ORM;
10
11
use Doctrine\Common\DataFixtures\FixtureInterface;
12
use Doctrine\Common\Persistence\ObjectManager;
13
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
14
use Webcook\Cms\SecurityBundle\Entity\User;
15
use Webcook\Cms\SecurityBundle\Entity\Role;
16
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
17
use Symfony\Component\DependencyInjection\ContainerInterface;
18
19
/**
20
 * User fixtures.
21
 */
22
class LoadUserData implements FixtureInterface, ContainerAwareInterface, OrderedFixtureInterface
23
{
24
    /**
25
     * System container.
26
     *
27
     * @var ContainerInterface
28
     */
29
    private $container;
30
31
    /**
32
     * Set container.
33
     *
34
     * @param ContainerInterface $container
35
     *                                      {@inheritDoc}
36
     */
37 49
    public function setContainer(ContainerInterface $container = null)
38
    {
39 49
        $this->container = $container;
40 49
    }
41
42
    /**
43
     * Load fixtures into db.
44
     *
45
     * {@inheritDoc}
46
     *
47
     * @param ObjectManager $manager
48
     */
49 49
    public function load(ObjectManager $manager)
50
    {
51 49
        $this->addAdmin($manager);
52 49
        $this->addEditor($manager);
53 49
        $this->addTestUser($manager);
54
55 49
        $manager->flush();
56 49
    }
57
58
    /**
59
     * Add admin user.
60
     *
61
     * @param ObjectManager $manager [description]
62
     */
63 49 View Code Duplication
    private function addAdmin($manager)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
64
    {
65 49
        $user = new User();
66
        
67 49
        $user->setUsername('admin');
68 49
        $user->setEmail('[email protected]');
69
70 49
        $factory = $this->container->get('security.encoder_factory');
71 49
        $encoder = $factory->getEncoder($user);
72 49
        $password = $encoder->encodePassword('test', $user->getSalt());
73 49
        $user->setPassword($password);
74
75 49
        $role = $manager->getRepository('Webcook\Cms\SecurityBundle\Entity\Role')->findAll();
76 49
        $user->addRole($role[0]);
77
78 49
        $manager->persist($user);
79 49
    }
80
81
    /**
82
     * Add editor user.
83
     *
84
     * @param ObjectManager $manager [description]
85
     */
86 49 View Code Duplication
    private function addEditor($manager)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
87
    {
88 49
        $user = new User();
89
90 49
        $user->setUsername('editor');
91 49
        $user->setEmail('[email protected]');
92
93 49
        $factory = $this->container->get('security.encoder_factory');
94 49
        $encoder = $factory->getEncoder($user);
95 49
        $password = $encoder->encodePassword('test', $user->getSalt());
96 49
        $user->setPassword($password);
97
98 49
        $role = $manager->getRepository('Webcook\Cms\SecurityBundle\Entity\Role')->findAll();
99 49
        $user->addRole($role[1]);
100
101 49
        $manager->persist($user);
102 49
    }
103
104
    /**
105
     * Add Test user.
106
     *
107
     * @param ObjectManager $manager [description]
108
     */
109 49 View Code Duplication
    private function addTestUser($manager)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
110
    {
111 49
        $user = new User();
112
113 49
        $user->setUsername('test');
114 49
        $user->setEmail('[email protected]');
115
116 49
        $factory = $this->container->get('security.encoder_factory');
117 49
        $encoder = $factory->getEncoder($user);
118 49
        $password = $encoder->encodePassword('test', $user->getSalt());
119 49
        $user->setPassword($password);
120
121 49
        $role = $manager->getRepository('Webcook\Cms\SecurityBundle\Entity\Role')->findAll();
122 49
        $user->addRole($role[0]);
123
124 49
        $manager->persist($user);
125 49
    }
126
127
128
    /**
129
     * Get fixture order.
130
     *
131
     * @return [type] [description]
0 ignored issues
show
Documentation introduced by
The doc-type [type] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
132
     */
133 49
    public function getOrder()
134
    {
135 49
        return 2;
136
    }
137
}
138