Conditions | 9 |
Paths | 37 |
Total Lines | 37 |
Code Lines | 23 |
Lines | 0 |
Ratio | 0 % |
Tests | 17 |
CRAP Score | 9 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
20 | 10 | public static function canUpdate(?User $currentUser, string $oldRole, string $newRole): bool |
|
21 | { |
||
22 | 10 | if ($newRole === $oldRole) { |
|
23 | 5 | return true; |
|
24 | } |
||
25 | |||
26 | 8 | $currentRole = $currentUser ? $currentUser->getRole() : User::ROLE_ANONYMOUS; |
|
27 | $orderedRoles = [ |
||
28 | 8 | User::ROLE_ANONYMOUS, |
|
29 | User::ROLE_INDIVIDUAL, |
||
30 | User::ROLE_MEMBER, |
||
31 | User::ROLE_TRAINER, |
||
32 | User::ROLE_BOOKING_ONLY, |
||
33 | User::ROLE_RESPONSIBLE, |
||
34 | User::ROLE_ADMINISTRATOR, |
||
35 | ]; |
||
36 | |||
37 | 8 | $newFound = false; |
|
38 | 8 | $oldFound = false; |
|
39 | 8 | foreach ($orderedRoles as $r) { |
|
40 | 8 | if ($r === $oldRole) { |
|
41 | 5 | $oldFound = true; |
|
42 | } |
||
43 | 8 | if ($r === $newRole) { |
|
44 | 4 | $newFound = true; |
|
45 | } |
||
46 | |||
47 | 8 | if ($r === $currentRole) { |
|
48 | 8 | break; |
|
49 | } |
||
50 | } |
||
51 | |||
52 | 8 | if (!$newFound || !$oldFound) { |
|
53 | 5 | return false; |
|
54 | } |
||
55 | |||
56 | 4 | return true; |
|
57 | } |
||
59 |