Manager::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

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
eloc 2
nc 1
nop 2
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @author enea dhack <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Enea\Authorization\Drivers\Cache;
13
14
use Enea\Authorization\Contracts\Owner;
15
use Enea\Authorization\Contracts\PermissionsOwner;
16
use Enea\Authorization\Contracts\RolesOwner;
17
use Enea\Authorization\Drivers\Cache\Repositories\PermissionRepository;
18
use Enea\Authorization\Drivers\Cache\Repositories\RoleRepository;
19
use Enea\Authorization\Drivers\ManagerContract;
20
use Illuminate\Support\Collection;
21
22
class Manager implements ManagerContract
23
{
24
    private $permissions;
25
26
    private $roles;
27
28 45
    public function __construct(PermissionRepository $permissions, RoleRepository $roles)
29
    {
30 45
        $this->permissions = $permissions;
31 45
        $this->roles = $roles;
32 45
    }
33
34 26
    public function permissions(PermissionsOwner $owner): Collection
35
    {
36 26
        return $this->permissions->toCollection($owner);
37
    }
38
39 17
    public function roles(RolesOwner $owner): Collection
40
    {
41 17
        return $this->roles->toCollection($owner);
42
    }
43
44 2
    public function forget(Owner $owner): void
45
    {
46 2
        if ($owner instanceof RolesOwner) {
47 1
            $this->roles->forget($owner);
48
        }
49
50 2
        if ($owner instanceof PermissionsOwner) {
51 1
            $this->permissions->forget($owner);
52
        }
53 2
    }
54
}
55