UsherRoleRepository   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 97
rs 10
c 1
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A all() 0 4 1
A create() 0 15 1
A find() 0 4 1
A update() 0 14 1
A delete() 0 6 1
A findByName() 0 4 1
1
<?php namespace Modules\User\Repositories\Usher;
2
3
use Maatwebsite\Usher\Contracts\Roles\RoleRepository as UsherRoleRepo;
4
use Modules\User\Repositories\RoleRepository;
5
6
class UsherRoleRepository implements RoleRepository
7
{
8
    /**
9
     * @var UsherRoleRepo
10
     */
11
    protected $role;
12
13
    /**
14
     * @param UsherRoleRepo $role
15
     */
16
    public function __construct(UsherRoleRepo $role)
17
    {
18
        $this->role = $role;
19
    }
20
21
    /**
22
     * Return all the roles
23
     * @return mixed
24
     */
25
    public function all()
26
    {
27
        return $this->role->all();
28
    }
29
30
    /**
31
     * Create a role resource
32
     * @return mixed
33
     */
34
    public function create($data)
35
    {
36
        $entity = $this->role->getClassName();
37
        $role = new $entity;
38
39
        $role->create(
40
            $data['name'],
41
            $data['permissions']
42
        );
43
44
        $this->role->persist($role);
45
        $this->role->flush();
46
47
        return $role;
48
    }
49
50
    /**
51
     * Find a role by its id
52
     * @param $id
53
     * @return mixed
54
     */
55
    public function find($id)
56
    {
57
        return $this->role->find($id);
58
    }
59
60
    /**
61
     * Update a role
62
     * @param $id
63
     * @param $data
64
     * @return mixed
65
     */
66
    public function update($id, $data)
67
    {
68
        $role = $this->role->find($id);
69
70
        $role->update(
71
            $data['name'],
72
            $data['permissions']
73
        );
74
75
        $this->role->persist($role);
76
        $this->role->flush();
77
78
        return $role;
79
    }
80
81
    /**
82
     * Delete a role
83
     * @param $id
84
     * @return mixed
85
     */
86
    public function delete($id)
87
    {
88
        $role = $this->find($id);
89
90
        return $this->role->delete($role);
91
    }
92
93
    /**
94
     * Find a role by its name
95
     * @param  string $name
96
     * @return mixed
97
     */
98
    public function findByName($name)
99
    {
100
        return $this->role->findByName($name);
101
    }
102
}
103