Completed
Push — develop ( c127f1...97f65e )
by Enea
03:21
created

Database   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 72.72%

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 26
ccs 8
cts 11
cp 0.7272
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A roles() 0 3 1
A forget() 0 4 1
A __construct() 0 4 1
A permissions() 0 3 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\GrantableOwner;
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\DatabaseContract;
20
use Illuminate\Support\Collection;
21
22
class Database implements DatabaseContract
23
{
24
    private $permissions;
25
26
    private $roles;
27
28 5
    public function __construct(PermissionRepository $permissions, RoleRepository $roles)
29
    {
30 5
        $this->permissions = $permissions;
31 5
        $this->roles = $roles;
32 5
    }
33
34 3
    public function permissions(PermissionsOwner $owner): Collection
35
    {
36 3
        return $this->permissions->toCollection($owner);
37
    }
38
39 2
    public function roles(RolesOwner $owner): Collection
40
    {
41 2
        return $this->roles->toCollection($owner);
42
    }
43
44
    public function forget(GrantableOwner $owner): void
45
    {
46
        $this->roles->forget($owner);
47
        $this->permissions->forget($owner);
48
    }
49
}
50