Total Complexity | 3 |
Total Lines | 22 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
9 | readonly class AuthorizationService |
||
|
|||
10 | { |
||
11 | /** |
||
12 | * @param UserRolesRepository $userRolesRepository |
||
13 | */ |
||
14 | 5 | public function __construct(private UserRolesRepository $userRolesRepository) |
|
15 | { |
||
16 | 5 | } |
|
17 | |||
18 | /** |
||
19 | * @param int $userId |
||
20 | * @param array $allowedRoles |
||
21 | * @return bool |
||
22 | */ |
||
23 | 5 | public function isUserRoleAuthorized(int $userId, array $allowedRoles): bool |
|
24 | { |
||
25 | try { |
||
26 | 5 | $userRole = $this->userRolesRepository->getUserRoles($userId); |
|
27 | 4 | return count(array_intersect((array)$userRole, $allowedRoles)) > 0; |
|
28 | 1 | } catch (Exception $exception) { |
|
29 | 1 | error_log('Exception occurred: ' . $exception->getMessage()); |
|
30 | 1 | return false; |
|
31 | } |
||
34 |