| Conditions | 12 |
| Paths | 11 |
| Total Lines | 43 |
| 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 |
||
| 64 | protected function voteOnAttribute($attribute, $subject, TokenInterface $token) |
||
| 65 | { |
||
| 66 | if (!$subject instanceof Agreement) { |
||
| 67 | return false; |
||
| 68 | } |
||
| 69 | |||
| 70 | // los administradores globales siempre tienen permiso |
||
| 71 | if ($this->decisionManager->decide($token, ['ROLE_ADMIN'])) { |
||
| 72 | return true; |
||
| 73 | } |
||
| 74 | |||
| 75 | /** @var User $user */ |
||
| 76 | $user = $token->getUser(); |
||
| 77 | |||
| 78 | if (!$user instanceof User) { |
||
| 79 | // si el usuario no ha entrado, denegar |
||
| 80 | return false; |
||
| 81 | } |
||
| 82 | |||
| 83 | // Si es el jefe de departamento, permitir siempre |
||
| 84 | if ($user->getDirects()->contains($subject->getStudent()->getStudentGroup()->getTraining()->getDepartment())) { |
||
| 85 | return true; |
||
| 86 | } |
||
| 87 | |||
| 88 | // Si es el tutor de grupo o tutor docente, permitir cualquier cosa salvo gestión |
||
| 89 | if ($user->getTutorizedGroups()->contains($subject->getStudent()->getStudentGroup()) |
||
| 90 | || $subject->getEducationalTutor() === $user) { |
||
| 91 | return $attribute !== self::MANAGE; |
||
| 92 | } |
||
| 93 | |||
| 94 | // Si es el tutor laboral, permitir acceso al calendario y al informe |
||
| 95 | if ($subject->getWorkTutor() === $user) { |
||
| 96 | return $attribute !== self::FILL && ($attribute === self::ACCESS || $attribute === self::REPORT); |
||
| 97 | } |
||
| 98 | |||
| 99 | // Si es propio usuario, denegar permitir sólo acceso |
||
| 100 | if ($subject->getStudent() === $user) { |
||
| 101 | return $attribute === self::ACCESS || $attribute === self::FILL; |
||
| 102 | } |
||
| 103 | |||
| 104 | // denegamos en cualquier otro caso |
||
| 105 | return false; |
||
| 106 | } |
||
| 107 | } |
||
| 108 |