Role   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 28
ccs 0
cts 6
cp 0
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A getRoles() 0 11 2
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