Passed
Push — main ( 52a9ba...b89683 )
by PRATIK
04:37 queued 14s
created

Video::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 14
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Adminetic\Website\Models\Admin;
4
5
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...
6
use Illuminate\Support\Facades\Cache;
7
use drh2so4\Thumbnail\Traits\Thumbnail;
0 ignored issues
show
Bug introduced by
The type drh2so4\Thumbnail\Traits\Thumbnail 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 Illuminate\Database\Eloquent\Model;
9
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...
10
11
class Video extends Model
12
{
13
    use LogsActivity, Thumbnail;
14
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
        Video::creating(function ($model) {
31
            $model->position = Video::max('position') + 1;
32
        });
33
    }
34
35
    // Cache Keys
36
    private static function cacheKey()
37
    {
38
        Cache::has('videos') ? Cache::forget('videos') : '';
39
    }
40
41
    // Appends
42
    protected $appends = ['video_html', 'network_thumbnail'];
43
44
    // Logs
45
    protected static $logName = 'video';
46
47
    public function getActivitylogOptions(): LogOptions
48
    {
49
        return LogOptions::defaults();
50
    }
51
52
    public function getVideoHtmlAttribute()
53
    {
54
        if (isset($this->url)) {
55
            return preg_replace("/\s*[a-zA-Z\/\/:\.]*youtube.com\/watch\?v=([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i", '<iframe width="420" height="315" src="//www.youtube.com/embed/$1" frameborder="0" allowfullscreen></iframe>', $this->url);
56
        }
57
    }
58
59
    public function getNetworkThumbnailAttribute()
60
    {
61
        return isset($this->thumbnail) ? url('storage/'.$this->thumbnail) : null;
62
    }
63
}
64