| Conditions | 10 |
| Paths | 8 |
| Total Lines | 37 |
| Code Lines | 23 |
| 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 |
||
| 31 | protected function addUserInCourse( |
||
| 32 | int $status, |
||
| 33 | User $user, |
||
| 34 | Course $course, |
||
| 35 | Session $session |
||
| 36 | ) { |
||
| 37 | if ($session->isActive() && |
||
| 38 | $user->getIsActive() && |
||
| 39 | $course->isActive() |
||
| 40 | ) { |
||
| 41 | if ($session->hasCourse($course)) { |
||
| 42 | switch ($status) { |
||
| 43 | case Session::DRH: |
||
| 44 | if ($user->hasRole('ROLE_RRHH')) { |
||
| 45 | $session->addUserInSession(Session::DRH, $user); |
||
| 46 | } |
||
| 47 | |||
| 48 | break; |
||
| 49 | case Session::STUDENT: |
||
| 50 | $session->addUserInSession(Session::STUDENT, $user); |
||
| 51 | $session->addUserInCourse( |
||
| 52 | Session::STUDENT, |
||
| 53 | $user, |
||
| 54 | $course |
||
| 55 | ); |
||
| 56 | |||
| 57 | break; |
||
| 58 | case Session::COACH: |
||
| 59 | if ($user->hasRole('ROLE_TEACHER')) { |
||
| 60 | $session->addUserInCourse( |
||
| 61 | Session::COACH, |
||
| 62 | $user, |
||
| 63 | $course |
||
| 64 | ); |
||
| 65 | } |
||
| 66 | |||
| 67 | break; |
||
| 68 | } |
||
| 73 |