Passed
Push — main ( 0c0937...7a01df )
by PRATIK
03:45
created

Block   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 12
c 1
b 0
f 1
dl 0
loc 32
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 14 1
A cacheKey() 0 3 2
1
<?php
2
3
namespace Adminetic\Website\Models\Admin;
4
5
use Illuminate\Support\Facades\Cache;
6
use Illuminate\Database\Eloquent\Model;
7
use Spatie\Activitylog\Traits\LogsActivity;
0 ignored issues
show
Bug introduced by
The type Spatie\Activitylog\Traits\LogsActivity was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
9
class Block extends Model
10
{
11
    use LogsActivity;
12
13
    protected $guarded = [];
14
15
    // Forget cache on updating or saving and deleting
16
    public static function boot()
17
    {
18
        parent::boot();
19
20
        static::saving(function () {
21
            self::cacheKey();
22
        });
23
24
        static::deleting(function () {
25
            self::cacheKey();
26
        });
27
28
        Block::creating(function ($model) {
29
            $model->position = Block::max('position') + 1;
30
        });
31
    }
32
33
    // Cache Keys
34
    private static function cacheKey()
35
    {
36
        Cache::has('blocks') ? Cache::forget('blocks') : '';
37
    }
38
39
    // Logs
40
    protected static $logName = 'block';
41
}
42