AdmineticUser   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
dl 0
loc 37
rs 10
c 1
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 10 1
A cacheKey() 0 3 2
A profile() 0 3 1
A getActivitylogOptions() 0 3 1
1
<?php
2
3
namespace Pratiksh\Adminetic\Traits;
4
5
use Illuminate\Support\Facades\Cache;
6
use Pratiksh\Adminetic\Models\Admin\Profile;
7
use Spatie\Activitylog\LogOptions;
8
use Spatie\Activitylog\Traits\LogsActivity;
9
10
/**
11
 * Adminetic User.
12
 */
13
trait AdmineticUser
14
{
15
    use HasPreference, HasRole, HasSlack, LogsActivity;
16
17
    // Forget cache on updating or saving and deleting
18
    public static function boot()
19
    {
20
        parent::boot();
21
22
        static::saving(function () {
23
            self::cacheKey();
24
        });
25
26
        static::deleting(function () {
27
            self::cacheKey();
28
        });
29
    }
30
31
    // Cache Keys
32
    private static function cacheKey()
33
    {
34
        Cache::has('users') ? Cache::forget('users') : '';
35
    }
36
37
    // Logs
38
    protected static $logName = 'user';
39
40
    public function getActivitylogOptions(): LogOptions
41
    {
42
        return LogOptions::defaults();
43
    }
44
45
    // Relations
46
47
    public function profile()
48
    {
49
        return $this->hasOne(Profile::class);
0 ignored issues
show
Bug introduced by
It seems like hasOne() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

49
        return $this->/** @scrutinizer ignore-call */ hasOne(Profile::class);
Loading history...
50
    }
51
}
52