Test Failed
Push — master ( 6b1c34...3b17fa )
by K
12:17 queued 10:29
created

AuthorizationService   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 22
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PerfectApp\RBAC;
6
7
use Exception;
8
9
readonly class AuthorizationService
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_READONLY on line 9 at column 0
Loading history...
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
        }
32
    }
33
}
34