SentinelRoleRepository   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A all() 0 4 1
A create() 0 4 1
A find() 0 4 1
A update() 0 10 1
A delete() 0 6 1
A findByName() 0 4 1
1
<?php namespace Modules\User\Repositories\Sentinel;
2
3
use Cartalyst\Sentinel\Laravel\Facades\Sentinel;
4
use Modules\User\Events\RoleWasUpdated;
5
use Modules\User\Repositories\RoleRepository;
6
7
class SentinelRoleRepository implements RoleRepository
8
{
9
    /**
10
     * @var \Cartalyst\Sentinel\Roles\EloquentRole
11
     */
12
    protected $role;
13
14
    public function __construct()
15
    {
16
        $this->role = Sentinel::getRoleRepository()->createModel();
17
    }
18
19
    /**
20
     * Return all the roles
21
     * @return mixed
22
     */
23
    public function all()
24
    {
25
        return $this->role->all();
26
    }
27
28
    /**
29
     * Create a role resource
30
     * @return mixed
31
     */
32
    public function create($data)
33
    {
34
        $this->role->create($data);
35
    }
36
37
    /**
38
     * Find a role by its id
39
     * @param $id
40
     * @return mixed
41
     */
42
    public function find($id)
43
    {
44
        return $this->role->find($id);
45
    }
46
47
    /**
48
     * Update a role
49
     * @param $id
50
     * @param $data
51
     * @return mixed
52
     */
53
    public function update($id, $data)
54
    {
55
        $role = $this->role->find($id);
56
57
        $role->fill($data);
58
59
        $role->save();
60
61
        event(new RoleWasUpdated($role));
62
    }
63
64
    /**
65
     * Delete a role
66
     * @param $id
67
     * @return mixed
68
     */
69
    public function delete($id)
70
    {
71
        $role = $this->role->find($id);
72
73
        return $role->delete();
74
    }
75
76
    /**
77
     * Find a role by its name
78
     * @param  string $name
79
     * @return mixed
80
     */
81
    public function findByName($name)
82
    {
83
        return Sentinel::findRoleByName($name);
84
    }
85
}
86