Conditions | 13 |
Paths | 13 |
Total Lines | 44 |
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 |
||
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 Message $message */ |
||
68 | $message = $subject; |
||
69 | |||
70 | switch ($attribute) { |
||
71 | case self::CREATE: |
||
72 | if ($message->getUserSender() === $user) { |
||
73 | return true; |
||
74 | } |
||
75 | |||
76 | break; |
||
77 | case self::VIEW: |
||
78 | if ($message->getUserReceiver() === $user) { |
||
79 | return true; |
||
80 | } |
||
81 | |||
82 | break; |
||
83 | case self::EDIT: |
||
84 | case self::DELETE: |
||
85 | if ($message->getUserReceiver() === $user && Message::MESSAGE_TYPE_INBOX === $message->getMsgType()) { |
||
86 | return true; |
||
87 | } |
||
88 | |||
89 | if ($message->getUserSender() === $user && Message::MESSAGE_TYPE_OUTBOX === $message->getMsgType()) { |
||
90 | return true; |
||
91 | } |
||
92 | |||
93 | break; |
||
94 | } |
||
95 | |||
96 | return false; |
||
97 | } |
||
99 |