| Conditions | 9 |
| Paths | 37 |
| Total Lines | 34 |
| Code Lines | 20 |
| 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_MEMBER, |
||
| 30 | User::ROLE_FACILITATOR, |
||
| 31 | User::ROLE_ADMINISTRATOR, |
||
| 32 | ]; |
||
| 33 | |||
| 34 | 8 | $newFound = false; |
|
| 35 | 8 | $oldFound = false; |
|
| 36 | 8 | foreach ($orderedRoles as $r) { |
|
| 37 | 8 | if ($r === $oldRole) { |
|
| 38 | 5 | $oldFound = true; |
|
| 39 | } |
||
| 40 | 8 | if ($r === $newRole) { |
|
| 41 | 4 | $newFound = true; |
|
| 42 | } |
||
| 43 | |||
| 44 | 8 | if ($r === $currentRole) { |
|
| 45 | 8 | break; |
|
| 46 | } |
||
| 47 | } |
||
| 48 | |||
| 49 | 8 | if (!$newFound || !$oldFound) { |
|
| 50 | 5 | return false; |
|
| 51 | } |
||
| 52 | |||
| 53 | 3 | return true; |
|
| 54 | } |
||
| 56 |