| Conditions | 11 |
| Paths | 10 |
| Total Lines | 48 |
| 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 |
||
| 52 | protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool |
||
| 53 | { |
||
| 54 | /** @var User $currentUser */ |
||
| 55 | $currentUser = $token->getUser(); |
||
| 56 | |||
| 57 | if (!$currentUser instanceof UserInterface) { |
||
| 58 | return false; |
||
| 59 | } |
||
| 60 | |||
| 61 | if ($this->security->isGranted('ROLE_ADMIN')) { |
||
| 62 | return true; |
||
| 63 | } |
||
| 64 | |||
| 65 | /** @var User $user */ |
||
| 66 | $user = $subject; |
||
| 67 | |||
| 68 | if (self::EDIT === $attribute) { |
||
| 69 | // Only the owner can edit private data |
||
| 70 | return (int) $currentUser->getId() === (int) $user->getId(); |
||
| 71 | } |
||
| 72 | |||
| 73 | if (self::VIEW === $attribute) { |
||
| 74 | if ((int) $currentUser->getId() === (int) $user->getId()) { |
||
| 75 | return true; |
||
| 76 | } |
||
| 77 | |||
| 78 | if ($user->hasFriendWithRelationType($currentUser, UserRelUser::USER_RELATION_TYPE_FRIEND)) { |
||
| 79 | return true; |
||
| 80 | } |
||
| 81 | |||
| 82 | $friendsOfFriends = $currentUser->getFriendsOfFriends(); |
||
| 83 | if (\in_array($user, $friendsOfFriends, true)) { |
||
| 84 | return true; |
||
| 85 | } |
||
| 86 | |||
| 87 | if ( |
||
| 88 | $user->hasFriendWithRelationType($currentUser, UserRelUser::USER_RELATION_TYPE_BOSS) |
||
| 89 | || $user->isFriendWithMeByRelationType($currentUser, UserRelUser::USER_RELATION_TYPE_BOSS) |
||
| 90 | ) { |
||
| 91 | return true; |
||
| 92 | } |
||
| 93 | |||
| 94 | if ($this->haveSharedMessages($currentUser, $user)) { |
||
| 95 | return true; |
||
| 96 | } |
||
| 97 | } |
||
| 98 | |||
| 99 | return false; |
||
| 100 | } |
||
| 121 |
This check looks for private methods that have been defined, but are not used inside the class.