| Conditions | 5 |
| Paths | 7 |
| Total Lines | 22 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 8 |
| CRAP Score | 5.2 |
| Changes | 0 | ||
| 1 | <?php |
||
| 35 | 3 | protected function voteOnAttribute($attribute, $subject, TokenInterface $token) |
|
| 36 | { |
||
| 37 | // our previous business logic indicates that admins can do it regardless |
||
| 38 | 3 | foreach ($token->getRoles() as $role) { |
|
| 39 | 2 | if (\in_array($role->getRole(), ['ROLE_ADMIN'])) { |
|
| 40 | 2 | return true; |
|
| 41 | } |
||
| 42 | } |
||
| 43 | |||
| 44 | // allow controller handle not found subject |
||
| 45 | 1 | if (null === $subject) { |
|
| 46 | return true; |
||
| 47 | } |
||
| 48 | |||
| 49 | 1 | $user = $token->getUser(); |
|
| 50 | |||
| 51 | // allow user to delete account |
||
| 52 | 1 | if ($user instanceof User) { |
|
| 53 | return $subject->getAuthor()->getId() === $user->getId(); |
||
| 54 | } |
||
| 55 | |||
| 56 | 1 | return false; |
|
| 57 | } |
||
| 59 |