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

AuthorizationService::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 1
dl 0
loc 2
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
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