PermissionManager   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 4
dl 0
loc 23
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A isAllowed() 0 10 1
1
<?php
2
declare(strict_types=1);
3
4
namespace SlayerBirden\DataFlowServer\Authorization\Service;
5
6
use Doctrine\Common\Collections\Criteria;
7
use Doctrine\Common\Collections\Selectable;
8
use SlayerBirden\DataFlowServer\Authorization\PermissionManagerInterface;
9
use SlayerBirden\DataFlowServer\Domain\Entities\User;
10
11
final class PermissionManager implements PermissionManagerInterface
12
{
13
    /**
14
     * @var Selectable
15
     */
16
    private $permissionRepository;
17
18 38
    public function __construct(Selectable $permissionRepository)
19
    {
20 38
        $this->permissionRepository = $permissionRepository;
21 38
    }
22
23 28
    public function isAllowed(string $resource, User $user): bool
24
    {
25 28
        $collection = $this->permissionRepository->matching(
26 28
            Criteria::create()
27 28
                ->where(Criteria::expr()->eq('user', $user))
28 28
                ->andWhere(Criteria::expr()->eq('resource', $resource))
29
        );
30
31 28
        return !$collection->isEmpty();
32
    }
33
}
34