Test Failed
Push — dev5 ( ba6069...125e24 )
by Ron
09:51
created

GetUserRoles::getRoleList()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 19
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 7
c 1
b 0
f 0
nc 5
nop 1
dl 0
loc 19
rs 10
1
<?php
2
3
namespace App\Domains\Users;
4
5
use Illuminate\Support\Facades\Auth;
6
7
use App\Http\Resources\UserRoleTypeCollection;
8
9
use App\UserRoleType;
10
11
class GetUserRoles
12
{
13
    //  Gather a list of roles available  if the limit is turned on, installer and admin roles will not be returned for lower level users
14
    public function getRoleList($limit = true)
15
    {
16
        $roles = new UserRoleTypeCollection(UserRoleType::all());
17
18
        if($limit)
19
        {
20
            if(Auth::user()->role_id !== 1)
21
            {
22
                $roles->forget(0);
0 ignored issues
show
Bug introduced by
The method forget() does not exist on App\Http\Resources\UserRoleTypeCollection. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

22
                $roles->/** @scrutinizer ignore-call */ 
23
                        forget(0);
Loading history...
23
            }
24
25
            //TOTO - Test this and make sure it is working
26
            if(Auth::user()->role_id > 2)
27
            {
28
                $roles->forget(1);
29
            }
30
        }
31
32
        return $roles;
33
    }
34
}
35