| Conditions | 11 |
| Paths | 11 |
| Total Lines | 38 |
| Code Lines | 19 |
| 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 |
||
| 51 | protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool |
||
| 52 | { |
||
| 53 | /** @var User $user */ |
||
| 54 | $user = $token->getUser(); |
||
| 55 | |||
| 56 | if (!$user instanceof UserInterface) { |
||
| 57 | return false; |
||
| 58 | } |
||
| 59 | |||
| 60 | // Admins have access to everything |
||
| 61 | if ($this->security->isGranted('ROLE_ADMIN')) { |
||
| 62 | return true; |
||
| 63 | } |
||
| 64 | |||
| 65 | /** @var Message $message */ |
||
| 66 | $message = $subject; |
||
| 67 | |||
| 68 | switch ($attribute) { |
||
| 69 | case self::VIEW: |
||
| 70 | if ($message->getUserReceiver() === $user) { |
||
| 71 | return true; |
||
| 72 | } |
||
| 73 | |||
| 74 | break; |
||
| 75 | case self::EDIT: |
||
| 76 | case self::DELETE: |
||
| 77 | if ($message->getUserReceiver() === $user && Message::MESSAGE_TYPE_INBOX === $message->getMsgType()) { |
||
| 78 | return true; |
||
| 79 | } |
||
| 80 | |||
| 81 | if ($message->getUserSender() === $user && Message::MESSAGE_TYPE_OUTBOX === $message->getMsgType()) { |
||
| 82 | return true; |
||
| 83 | } |
||
| 84 | |||
| 85 | break; |
||
| 86 | } |
||
| 87 | |||
| 88 | return false; |
||
| 89 | } |
||
| 91 |