| Conditions | 13 |
| Paths | 12 |
| Total Lines | 51 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 53 | protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool |
||
| 54 | { |
||
| 55 | /** @var User $user */ |
||
| 56 | $user = $token->getUser(); |
||
| 57 | |||
| 58 | if (!$user instanceof UserInterface) { |
||
| 59 | return false; |
||
| 60 | } |
||
| 61 | |||
| 62 | // Admins have access to everything. |
||
| 63 | if ($this->security->isGranted('ROLE_ADMIN')) { |
||
| 64 | return true; |
||
| 65 | } |
||
| 66 | |||
| 67 | /** @var UserRelUser $userRelUser */ |
||
| 68 | $userRelUser = $subject; |
||
| 69 | |||
| 70 | switch ($attribute) { |
||
| 71 | case self::CREATE: |
||
| 72 | if ($userRelUser->getUser() === $user) { |
||
| 73 | return true; |
||
| 74 | } |
||
| 75 | |||
| 76 | break; |
||
| 77 | case self::EDIT: |
||
| 78 | if ($userRelUser->getUser() === $user) { |
||
| 79 | return true; |
||
| 80 | } |
||
| 81 | |||
| 82 | if ($userRelUser->getFriend() === $user && |
||
| 83 | UserRelUser::USER_RELATION_TYPE_FRIEND_REQUEST === $userRelUser->getRelationType() |
||
| 84 | ) { |
||
| 85 | return true; |
||
| 86 | } |
||
| 87 | |||
| 88 | break; |
||
| 89 | case self::VIEW: |
||
| 90 | return true; |
||
| 91 | case self::DELETE: |
||
| 92 | if ($userRelUser->getUser() === $user) { |
||
| 93 | return true; |
||
| 94 | } |
||
| 95 | |||
| 96 | if ($userRelUser->getFriend() === $user) { |
||
| 97 | return true; |
||
| 98 | } |
||
| 99 | |||
| 100 | break; |
||
| 101 | } |
||
| 102 | |||
| 103 | return false; |
||
| 104 | } |
||
| 106 |