Passed
Push — master ( 62083f...ad8d4a )
by Julito
10:31
created

GroupFixtures::load()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 63
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 38
nc 4
nop 1
dl 0
loc 63
rs 9.312
c 1
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CoreBundle\DataFixtures;
8
9
use Chamilo\CoreBundle\Entity\Group;
10
use Doctrine\Bundle\FixturesBundle\Fixture;
11
use Doctrine\Persistence\ObjectManager;
12
13
class GroupFixtures extends Fixture
14
{
15
    public function load(ObjectManager $manager): void
16
    {
17
        $groups = [
18
            [
19
                'code' => 'ADMIN',
20
                'title' => 'Administrators',
21
                'roles' => ['ROLE_ADMIN'],
22
            ],
23
            [
24
                'code' => 'STUDENT',
25
                'title' => 'Students',
26
                'roles' => ['ROLE_STUDENT'],
27
            ],
28
            [
29
                'code' => 'TEACHER',
30
                'title' => 'Teachers',
31
                'roles' => ['ROLE_TEACHER'],
32
            ],
33
            [
34
                'code' => 'RRHH',
35
                'title' => 'Human resources manager',
36
                'roles' => ['ROLE_RRHH'],
37
            ],
38
            [
39
                'code' => 'SESSION_MANAGER',
40
                'title' => 'Session',
41
                'roles' => ['ROLE_SESSION_MANAGER'],
42
            ],
43
            [
44
                'code' => 'QUESTION_MANAGER',
45
                'title' => 'Question manager',
46
                'roles' => ['ROLE_QUESTION_MANAGER'],
47
            ],
48
            [
49
                'code' => 'STUDENT_BOSS',
50
                'title' => 'Student boss',
51
                'roles' => ['ROLE_STUDENT_BOSS'],
52
            ],
53
            [
54
                'code' => 'INVITEE',
55
                'title' => 'Invitee',
56
                'roles' => ['ROLE_INVITEE'],
57
            ],
58
        ];
59
        $repo = $manager->getRepository(Group::class);
60
        foreach ($groups as $groupData) {
61
            $criteria = [
62
                'code' => $groupData['code'],
63
            ];
64
            $groupExists = $repo->findOneBy($criteria);
65
            if (!$groupExists) {
66
                $group = new Group($groupData['title']);
67
                $group
68
                    ->setCode($groupData['code'])
69
                ;
70
71
                foreach ($groupData['roles'] as $role) {
72
                    $group->addRole($role);
73
                }
74
                $manager->persist($group);
75
            }
76
        }
77
        $manager->flush();
78
    }
79
}
80