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

Gallery::__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
use Spatie\MediaLibrary\HasMedia;
0 ignored issues
show
Bug introduced by
The type Spatie\MediaLibrary\HasMedia 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...
10
use Spatie\MediaLibrary\InteractsWithMedia;
0 ignored issues
show
Bug introduced by
The type Spatie\MediaLibrary\InteractsWithMedia 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...
11
12
class Gallery extends Model implements HasMedia
13
{
14
    use LogsActivity, InteractsWithMedia;
15
    protected $guarded = [];
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('galleries') ? Cache::forget('galleries') : '';
35
        Cache::has('slider') ? Cache::forget('slider') : '';
36
    }
37
38
    // Logs
39
    protected static $logName = 'gallery';
40
41
    public function getActivitylogOptions(): LogOptions
42
    {
43
        return LogOptions::defaults();
44
    }
45
46
    protected $casts = [
47
        'videos' => 'array',
48
    ];
49
50
    public function __construct(array $attributes = [])
51
    {
52
        $this->table = config('website.table_prefix', 'website') . '_galleries';
53
54
        parent::__construct($attributes);
55
    }
56
57
58
    // Accessors
59
    public function getImagesAttribute()
60
    {
61
        return !is_null($this->getMedia('images')) ? $this->getMedia('images') : null;
62
    }
63
}
64