| Conditions | 3 |
| Paths | 3 |
| Total Lines | 93 |
| Code Lines | 64 |
| 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 | $roles = [ |
||
| 18 | [ |
||
| 19 | 'code' => 'INVITEE', |
||
| 20 | 'constantValue' => 1, |
||
| 21 | 'title' => 'Invitee', |
||
| 22 | 'description' => 'Invited users', |
||
| 23 | 'systemRole' => true, |
||
| 24 | ], |
||
| 25 | [ |
||
| 26 | 'code' => 'STUDENT', |
||
| 27 | 'constantValue' => 2, |
||
| 28 | 'title' => 'Student', |
||
| 29 | 'description' => 'Students of courses or sessions', |
||
| 30 | 'systemRole' => true, |
||
| 31 | ], |
||
| 32 | [ |
||
| 33 | 'code' => 'TEACHER', |
||
| 34 | 'constantValue' => 3, |
||
| 35 | 'title' => 'Teacher', |
||
| 36 | 'description' => 'Teachers of courses or sessions', |
||
| 37 | 'systemRole' => true, |
||
| 38 | ], |
||
| 39 | [ |
||
| 40 | 'code' => 'ADMIN', |
||
| 41 | 'constantValue' => 4, |
||
| 42 | 'title' => 'Administrator', |
||
| 43 | 'description' => 'Platform administrators', |
||
| 44 | 'systemRole' => true, |
||
| 45 | ], |
||
| 46 | [ |
||
| 47 | 'code' => 'SUPER_ADMIN', |
||
| 48 | 'constantValue' => 5, |
||
| 49 | 'title' => 'Super Administrator', |
||
| 50 | 'description' => 'Super admin users', |
||
| 51 | 'systemRole' => true, |
||
| 52 | ], |
||
| 53 | [ |
||
| 54 | 'code' => 'GLOBAL_ADMIN', |
||
| 55 | 'constantValue' => 6, |
||
| 56 | 'title' => 'Global Administrator', |
||
| 57 | 'description' => 'Global admin users', |
||
| 58 | 'systemRole' => true, |
||
| 59 | ], |
||
| 60 | [ |
||
| 61 | 'code' => 'HR', |
||
| 62 | 'constantValue' => 7, |
||
| 63 | 'title' => 'HR Manager', |
||
| 64 | 'description' => 'Human resources managers', |
||
| 65 | 'systemRole' => false, |
||
| 66 | ], |
||
| 67 | [ |
||
| 68 | 'code' => 'QUESTION_MANAGER', |
||
| 69 | 'constantValue' => 8, |
||
| 70 | 'title' => 'Question Bank Manager', |
||
| 71 | 'description' => 'Manages the question bank across courses', |
||
| 72 | 'systemRole' => false, |
||
| 73 | ], |
||
| 74 | [ |
||
| 75 | 'code' => 'SESSION_MANAGER', |
||
| 76 | 'constantValue' => 9, |
||
| 77 | 'title' => 'Session Manager', |
||
| 78 | 'description' => 'Manages sessions and session content', |
||
| 79 | 'systemRole' => false, |
||
| 80 | ], |
||
| 81 | [ |
||
| 82 | 'code' => 'STUDENT_BOSS', |
||
| 83 | 'constantValue' => 10, |
||
| 84 | 'title' => 'Student Boss', |
||
| 85 | 'description' => 'Manages groups of students', |
||
| 86 | 'systemRole' => false, |
||
| 87 | ], |
||
| 88 | ]; |
||
| 89 | |||
| 90 | foreach ($roles as $roleData) { |
||
| 91 | $existing = $manager->getRepository(Role::class) |
||
| 92 | ->findOneBy(['code' => $roleData['code']]); |
||
| 93 | |||
| 94 | if ($existing) { |
||
| 95 | continue; |
||
| 96 | } |
||
| 97 | |||
| 98 | $role = new Role(); |
||
| 99 | $role->setCode($roleData['code']); |
||
| 100 | $role->setConstantValue($roleData['constantValue']); |
||
| 101 | $role->setTitle($roleData['title']); |
||
| 102 | $role->setDescription($roleData['description']); |
||
| 103 | $role->setSystemRole($roleData['systemRole']); |
||
| 104 | $manager->persist($role); |
||
| 105 | } |
||
| 106 | |||
| 107 | $manager->flush(); |
||
| 108 | } |
||
| 110 |