Passed
Push — main ( 8b26fd...cdf646 )
by PRATIK
04:10
created

Block::setting()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 3
c 1
b 0
f 1
nc 2
nop 0
dl 0
loc 5
rs 10
1
<?php
2
3
namespace Adminetic\Website\Models\Admin;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Support\Facades\Cache;
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
    public function setting()
43
    {
44
        return isset($this->setting)
45
            ? json_decode($this->setting)
0 ignored issues
show
Bug introduced by
$this->setting of type array is incompatible with the type string expected by parameter $json of json_decode(). ( Ignorable by Annotation )

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

45
            ? json_decode(/** @scrutinizer ignore-type */ $this->setting)
Loading history...
46
            : null;
47
    }
48
}
49