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