Completed
Push — master ( cf2713...aee5ae )
by Sherif
02:07
created

UserRepository   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A detachRoles() 0 5 2
A attachRoles() 0 5 2
A countRoles() 0 5 2
1
<?php namespace App\Modules\Users\Repositories;
2
3
use App\Modules\Core\BaseClasses\BaseRepository;
4
use Illuminate\Support\Arr;
5
use App\Modules\Users\AclUser;
6
7
class UserRepository extends BaseRepository
8
{
9
    /**
10
     * Init new object.
11
     *
12
     * @param   AclUser $model
13
     * @return  void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
14
     */
15
    public function __construct(AclUser $model)
16
    {
17
        parent::__construct($model);
18
    }
19
20
    /**
21
     * Detach all roles from the given role.
22
     *
23
     * @param  mixed $role
24
     * @return object
25
     */
26
    public function detachRoles($role)
27
    {
28
        $role = ! is_int($role) ? $role : $this->find($role);
29
        $role->roles()->detach();
30
    }
31
32
    /**
33
     * Attach role ids to the given role.
34
     *
35
     * @param  mixed $role
36
     * @param  array $roleIds
37
     * @return object
38
     */
39
    public function attachRoles($role, $roleIds)
40
    {
41
        $role = ! is_int($role) ? $role : $this->find($role);
42
        $role->roles()->attach($roleIds);
43
    }
44
45
    /**
46
     * Count the given user the given roles.
47
     *
48
     * @param  mixed    $user
49
     * @param  string[] $roles
50
     * @return boolean
51
     */
52
    public function countRoles($user, $roles)
53
    {
54
        $user = ! is_int($user) ? $user : $this->find($user);
55
        return $user->roles()->whereIn('name', $roles)->count();
56
    }
57
}
58