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