Conditions | 10 |
Paths | 9 |
Total Lines | 47 |
Code Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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->getSender() === $user) { |
||
73 | return true; |
||
74 | } |
||
75 | |||
76 | break; |
||
77 | case self::VIEW: |
||
78 | if ($message->hasReceiver($user) || $message->getSender() === $user) { |
||
79 | return true; |
||
80 | } |
||
81 | |||
82 | break; |
||
83 | case self::EDIT: |
||
84 | case self::DELETE: |
||
85 | // @todo |
||
86 | break; |
||
87 | /*if ($message->hasReceiver($user) && |
||
88 | Message::MESSAGE_TYPE_INBOX === $message->getMsgType() |
||
89 | ) { |
||
90 | return true; |
||
91 | }*/ |
||
92 | |||
93 | // User cannot delete. |
||
94 | /*if ($message->getSender() === $user && Message::MESSAGE_TYPE_OUTBOX === $message->getMsgType()) { |
||
95 | return true; |
||
96 | }*/ |
||
97 | } |
||
98 | |||
99 | return false; |
||
100 | } |
||
102 |