| Conditions | 4 |
| Paths | 4 |
| Total Lines | 69 |
| Code Lines | 40 |
| 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 |
||
| 36 | public function createDefaultGroups(AccessGroupFixtures $accessGroupFixtures = null): void |
||
| 37 | { |
||
| 38 | $groups = [ |
||
| 39 | [ |
||
| 40 | 'code' => 'ADMIN', |
||
| 41 | 'title' => 'Administrators', |
||
| 42 | 'roles' => ['ROLE_ADMIN'], |
||
| 43 | ], |
||
| 44 | [ |
||
| 45 | 'code' => 'STUDENT', |
||
| 46 | 'title' => 'Students', |
||
| 47 | 'roles' => ['ROLE_STUDENT'], |
||
| 48 | ], |
||
| 49 | [ |
||
| 50 | 'code' => 'TEACHER', |
||
| 51 | 'title' => 'Teachers', |
||
| 52 | 'roles' => ['ROLE_TEACHER'], |
||
| 53 | ], |
||
| 54 | [ |
||
| 55 | 'code' => 'RRHH', |
||
| 56 | 'title' => 'Human resources manager', |
||
| 57 | 'roles' => ['ROLE_RRHH'], |
||
| 58 | ], |
||
| 59 | [ |
||
| 60 | 'code' => 'SESSION_MANAGER', |
||
| 61 | 'title' => 'Session', |
||
| 62 | 'roles' => ['ROLE_SESSION_MANAGER'], |
||
| 63 | ], |
||
| 64 | [ |
||
| 65 | 'code' => 'QUESTION_MANAGER', |
||
| 66 | 'title' => 'Question manager', |
||
| 67 | 'roles' => ['ROLE_QUESTION_MANAGER'], |
||
| 68 | ], |
||
| 69 | [ |
||
| 70 | 'code' => 'STUDENT_BOSS', |
||
| 71 | 'title' => 'Student boss', |
||
| 72 | 'roles' => ['ROLE_STUDENT_BOSS'], |
||
| 73 | ], |
||
| 74 | [ |
||
| 75 | 'code' => 'INVITEE', |
||
| 76 | 'title' => 'Invitee', |
||
| 77 | 'roles' => ['ROLE_INVITEE'], |
||
| 78 | ], |
||
| 79 | ]; |
||
| 80 | |||
| 81 | $manager = $this->getEntityManager(); |
||
| 82 | |||
| 83 | $repo = $manager->getRepository(Group::class); |
||
| 84 | foreach ($groups as $groupData) { |
||
| 85 | $criteria = [ |
||
| 86 | 'code' => $groupData['code'], |
||
| 87 | ]; |
||
| 88 | $groupExists = $repo->findOneBy($criteria); |
||
| 89 | if (!$groupExists) { |
||
| 90 | $group = new Group($groupData['title']); |
||
| 91 | $group |
||
| 92 | ->setCode($groupData['code']) |
||
| 93 | ; |
||
| 94 | |||
| 95 | foreach ($groupData['roles'] as $role) { |
||
| 96 | $group->addRole($role); |
||
| 97 | } |
||
| 98 | $manager->persist($group); |
||
| 99 | |||
| 100 | $accessGroupFixtures->addReference('GROUP_'.$groupData['code'], $group); |
||
|
|
|||
| 101 | } |
||
| 102 | } |
||
| 103 | |||
| 104 | $manager->flush(); |
||
| 105 | } |
||
| 107 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.