Role::getRoles()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 11
ccs 0
cts 6
cp 0
crap 6
rs 10
1
<?php
2
3
namespace App\Models;
4
5
use Illuminate\Database\Eloquent\Factories\HasFactory;
6
use Illuminate\Support\Arr;
7
use Illuminate\Support\Facades\Auth;
8
use Spatie\Permission\Models\Role as BaseRole;
9
10
/**
11
 * @property int $id
12
 * @property \Illuminate\Support\Carbon $created_at
13
 * @property \Illuminate\Support\Carbon $updated_at
14
 */
15
class Role extends BaseRole implements Concerns\Role\Attribute
16
{
17
    use HasFactory;
18
19
    /**
20
     * {@inheritDoc}
21
     */
22
    protected $fillable = [
23
        'name',
24
        'guard_name',
25
    ];
26
27
    /**
28
     * Return list of role based on the authenticated user.
29
     *
30
     * @return string[]
31
     */
32
    public static function getRoles(): array
33
    {
34
        /** @var \App\Models\User $user */
35
        $user = Auth::user();
36
        $roles = static::ROLES;
37
38
        if ($user->hasRole(static::ROLE_STAFF)) {
39
            $roles = Arr::except($roles, static::ROLE_ADMIN);
40
        }
41
42
        return $roles;
43
    }
44
}
45