| Conditions | 4 |
| Paths | 1 |
| Total Lines | 30 |
| Code Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 16 |
| CRAP Score | 4 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 15 | 3 | public static function build(): array |
|
| 16 | { |
||
| 17 | return |
||
| 18 | [ |
||
| 19 | 1 | 'name' => 'userRolesAvailable', |
|
| 20 | 1 | 'type' => Type::nonNull(Type::listOf(Type::nonNull(_types()->get(UserRoleType::class)))), |
|
| 21 | 1 | 'description' => 'List of roles available for the given user', |
|
| 22 | 'args' => [ |
||
| 23 | [ |
||
| 24 | 1 | 'name' => 'user', |
|
| 25 | 1 | 'type' => _types()->getId(User::class), |
|
| 26 | ], |
||
| 27 | ], |
||
| 28 | 1 | 'resolve' => function ($root, array $args): array { |
|
| 29 | 3 | $currentUser = User::getCurrent(); |
|
| 30 | 3 | $oldRole = isset($args['user']) ? $args['user']->getEntity()->getRole() : User::ROLE_MEMBER; |
|
| 31 | |||
| 32 | /** @var UserRoleType $type */ |
||
| 33 | 3 | $type = _types()->get(UserRoleType::class); |
|
| 34 | |||
| 35 | // Check each roles that exist in our API (which is different from the roles that exist in our DB) |
||
| 36 | 3 | $available = []; |
|
| 37 | 3 | foreach ($type->getValues() as $valueDefinition) { |
|
| 38 | 3 | $newRole = $valueDefinition->value; |
|
| 39 | 3 | if (Role::canUpdate($currentUser, $oldRole, $newRole)) { |
|
| 40 | 3 | $available[] = $newRole; |
|
| 41 | } |
||
| 42 | } |
||
| 43 | |||
| 44 | 3 | return $available; |
|
| 45 | 1 | }, |
|
| 49 |