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 |
||
100 | protected function addUserInCourse( |
||
101 | int $status, |
||
102 | User $user, |
||
103 | Course $course, |
||
104 | Session $session |
||
105 | ): void { |
||
106 | if ($session->isActive() && |
||
107 | $user->getIsActive() && |
||
108 | $course->isActive() && $session->hasCourse($course) |
||
109 | ) { |
||
110 | switch ($status) { |
||
111 | case Session::DRH: |
||
112 | if ($user->hasRole('ROLE_RRHH')) { |
||
113 | $session->addUserInSession(Session::DRH, $user); |
||
114 | } |
||
115 | |||
116 | break; |
||
117 | case Session::STUDENT: |
||
118 | $session->addUserInSession(Session::STUDENT, $user); |
||
119 | $session->addUserInCourse( |
||
120 | Session::STUDENT, |
||
121 | $user, |
||
122 | $course |
||
123 | ); |
||
124 | |||
125 | break; |
||
126 | case Session::COACH: |
||
127 | if ($user->hasRole('ROLE_TEACHER')) { |
||
128 | $session->addUserInCourse( |
||
129 | Session::COACH, |
||
130 | $user, |
||
131 | $course |
||
132 | ); |
||
133 | } |
||
134 | |||
135 | break; |
||
136 | } |
||
158 |