| Conditions | 11 |
| Paths | 12 |
| Total Lines | 53 |
| Code Lines | 24 |
| 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 |
||
| 65 | protected function voteOnAttribute($attribute, $subject, TokenInterface $token) |
||
| 66 | { |
||
| 67 | if (!$subject instanceof Entry) { |
||
| 68 | return false; |
||
| 69 | } |
||
| 70 | |||
| 71 | // los administradores globales siempre tienen permiso |
||
| 72 | if ($this->extensionService->isUserGlobalAdministrator()) { |
||
| 73 | return true; |
||
| 74 | } |
||
| 75 | |||
| 76 | /** @var User $user */ |
||
| 77 | $user = $token->getUser(); |
||
| 78 | |||
| 79 | if (!$user instanceof User) { |
||
| 80 | // si el usuario no ha entrado, denegar |
||
| 81 | return false; |
||
| 82 | } |
||
| 83 | |||
| 84 | $organization = $this->extensionService->getCurrentOrganization(); |
||
| 85 | |||
| 86 | // si la carpeta no pertence a la organización actual, denegar |
||
| 87 | if ($organization !== $subject->getFolder()->getOrganization()) { |
||
| 88 | return true; |
||
| 89 | } |
||
| 90 | |||
| 91 | // si es administrador de la organización, permitir siempre |
||
| 92 | if ($this->extensionService->isUserLocalAdministrator()) { |
||
| 93 | return true; |
||
| 94 | } |
||
| 95 | |||
| 96 | $table = [ |
||
| 97 | self::ACCESS => FolderVoter::ACCESS, |
||
| 98 | self::APPROVE => FolderVoter::APPROVE, |
||
| 99 | self::REVIEW => FolderVoter::REVIEW, |
||
| 100 | self::REQUEST_CHANGES => FolderVoter::REQUEST_CHANGES, |
||
| 101 | ]; |
||
| 102 | |||
| 103 | // todos los permisos salvo el de gestión se admiten si se tiene el mismo permiso para la carpeta |
||
| 104 | if (isset($table[$attribute])) { |
||
| 105 | return $this->accessDecisionManager->decide($token, [$table[$attribute]], $subject->getFolder()); |
||
| 106 | } |
||
| 107 | |||
| 108 | // se permite la gestión si es el creador del documento original y no tiene revisión activa |
||
| 109 | // o si es el creador de la revisión activa |
||
| 110 | if (self::MANAGE === $attribute) { |
||
| 111 | return (!$subject->getCurrentVersion() && $subject->getCreatedBy() === $user) || |
||
| 112 | ($subject->getCurrentVersion() && $subject->getCurrentVersion()->getCreatedBy() === $user); |
||
| 113 | } |
||
| 114 | |||
| 115 | // denegar en otro caso |
||
| 116 | return false; |
||
| 117 | } |
||
| 118 | } |
||
| 119 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.