PermissionManager::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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