Passed
Push — main ( 6877e3...35b0cf )
by PRATIK
04:14
created

Video::cacheKey()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 2
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Adminetic\Website\Models\Admin;
4
5
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...
6
use Illuminate\Database\Eloquent\Model;
7
use Illuminate\Support\Facades\Cache;
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 Video extends Model
11
{
12
    use LogsActivity, Thumbnail;
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
        Video::creating(function ($model) {
30
            $model->position = Video::max('position') + 1;
31
        });
32
    }
33
34
    // Cache Keys
35
    private static function cacheKey()
36
    {
37
        Cache::has('videos') ? Cache::forget('videos') : '';
38
    }
39
40
    // Appends
41
    protected $appends = ['video_html'];
42
43
    // Logs
44
    protected static $logName = 'video';
45
46
    public function getVideoHtmlAttribute()
47
    {
48
        if (isset($this->url)) {
49
            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);
50
        }
51
    }
52
}
53