| Conditions | 4 |
| Paths | 4 |
| Total Lines | 63 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 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 | } |
||
| 80 |