Conditions | 5 |
Paths | 6 |
Total Lines | 66 |
Code Lines | 37 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
48 | public function createDefaultGroups(AccessGroupFixtures $accessGroupFixtures = null): void |
||
49 | { |
||
50 | $groups = [ |
||
51 | [ |
||
52 | 'code' => 'ADMIN', |
||
53 | 'title' => 'Administrators', |
||
54 | 'roles' => ['ROLE_ADMIN'], |
||
55 | ], |
||
56 | [ |
||
57 | 'code' => 'STUDENT', |
||
58 | 'title' => 'Students', |
||
59 | 'roles' => ['ROLE_STUDENT'], |
||
60 | ], |
||
61 | [ |
||
62 | 'code' => 'TEACHER', |
||
63 | 'title' => 'Teachers', |
||
64 | 'roles' => ['ROLE_TEACHER'], |
||
65 | ], |
||
66 | [ |
||
67 | 'code' => 'RRHH', |
||
68 | 'title' => 'Human resources manager', |
||
69 | 'roles' => ['ROLE_RRHH'], |
||
70 | ], |
||
71 | [ |
||
72 | 'code' => 'SESSION_MANAGER', |
||
73 | 'title' => 'Session', |
||
74 | 'roles' => ['ROLE_SESSION_MANAGER'], |
||
75 | ], |
||
76 | [ |
||
77 | 'code' => 'QUESTION_MANAGER', |
||
78 | 'title' => 'Question manager', |
||
79 | 'roles' => ['ROLE_QUESTION_MANAGER'], |
||
80 | ], |
||
81 | [ |
||
82 | 'code' => 'STUDENT_BOSS', |
||
83 | 'title' => 'Student boss', |
||
84 | 'roles' => ['ROLE_STUDENT_BOSS'], |
||
85 | ], |
||
86 | [ |
||
87 | 'code' => 'INVITEE', |
||
88 | 'title' => 'Invitee', |
||
89 | 'roles' => ['ROLE_INVITEE'], |
||
90 | ], |
||
91 | ]; |
||
92 | |||
93 | $manager = $this->getEntityManager(); |
||
94 | |||
95 | foreach ($groups as $groupData) { |
||
96 | $groupExists = $this->findOneBy(['code' => $groupData['code']]); |
||
97 | if (null === $groupExists) { |
||
98 | $group = (new Group($groupData['title'])) |
||
99 | ->setCode($groupData['code']) |
||
100 | ; |
||
101 | |||
102 | foreach ($groupData['roles'] as $role) { |
||
103 | $group->addRole($role); |
||
104 | } |
||
105 | $manager->persist($group); |
||
106 | |||
107 | if (null !== $accessGroupFixtures) { |
||
108 | $accessGroupFixtures->addReference('GROUP_'.$groupData['code'], $group); |
||
109 | } |
||
110 | } |
||
111 | } |
||
112 | |||
113 | $manager->flush(); |
||
114 | } |
||
116 |