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