| Conditions | 10 |
| Paths | 7 |
| Total Lines | 36 |
| Code Lines | 22 |
| 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 |
||
| 86 | protected function addUserInCourse( |
||
| 87 | int $status, |
||
| 88 | User $user, |
||
| 89 | Course $course, |
||
| 90 | Session $session |
||
| 91 | ): void { |
||
| 92 | if ($session->isActive() && |
||
| 93 | $user->getIsActive() && |
||
| 94 | $course->isActive() && $session->hasCourse($course) |
||
| 95 | ) { |
||
| 96 | switch ($status) { |
||
| 97 | case Session::DRH: |
||
| 98 | if ($user->hasRole('ROLE_RRHH')) { |
||
| 99 | $session->addUserInSession(Session::DRH, $user); |
||
| 100 | } |
||
| 101 | |||
| 102 | break; |
||
| 103 | case Session::STUDENT: |
||
| 104 | $session->addUserInSession(Session::STUDENT, $user); |
||
| 105 | $session->addUserInCourse( |
||
| 106 | Session::STUDENT, |
||
| 107 | $user, |
||
| 108 | $course |
||
| 109 | ); |
||
| 110 | |||
| 111 | break; |
||
| 112 | case Session::COACH: |
||
| 113 | if ($user->hasRole('ROLE_TEACHER')) { |
||
| 114 | $session->addUserInCourse( |
||
| 115 | Session::COACH, |
||
| 116 | $user, |
||
| 117 | $course |
||
| 118 | ); |
||
| 119 | } |
||
| 120 | |||
| 121 | break; |
||
| 122 | } |
||
| 144 |