Passed
Push — main ( 93d181...6c645c )
by PRATIK
15:49
created

Attribute::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
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\LogOptions;
0 ignored issues
show
Bug introduced by
The type Spatie\Activitylog\LogOptions 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
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...
9
10
class Attribute extends Model
11
{
12
    use LogsActivity;
13
14
    protected $guarded = [];
15
16
    // Forget cache on updating or saving and deleting
17
    public static function boot()
18
    {
19
        parent::boot();
20
21
        static::saving(function () {
22
            self::cacheKey();
23
        });
24
25
        static::deleting(function () {
26
            self::cacheKey();
27
        });
28
    }
29
30
    // Cache Keys
31
    private static function cacheKey()
32
    {
33
        Cache::has('attributes') ? Cache::forget('attributes') : '';
34
    }
35
36
    // Logs
37
    protected static $logName = 'attribute';
38
39
    public function getActivitylogOptions(): LogOptions
40
    {
41
        return LogOptions::defaults();
42
    }
43
44
45
    public function __construct(array $attributes = [])
46
    {
47
        $this->table = config('website.table_prefix', 'website') . '_attributes';
48
49
        parent::__construct($attributes);
50
    }
51
52
    // Casts
53
    protected $casts = [
54
        'values' => 'array',
55
    ];
56
57
    // Relationships
58
    public function products()
59
    {
60
        return $this->belongsToMany(Product::class)->withPivot('values')->withTimestamps();
61
    }
62
}
63