Passed
Push — main ( d80ffe...007845 )
by PRATIK
04:47
created

Category::getActivitylogOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Adminetic\Website\Models\Admin;
4
5
use App\Traits\CategoryMorphedByMany;
0 ignored issues
show
Bug introduced by
The type App\Traits\CategoryMorphedByMany 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 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...
7
use Illuminate\Database\Eloquent\Model;
8
use Illuminate\Support\Facades\Cache;
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 Category extends Model
12
{
13
    use LogsActivity, Thumbnail, CategoryMorphedByMany;
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
        Category::creating(function ($model) {
31
            $model->position = Category::max('position') + 1;
32
        });
33
    }
34
35
    // Cache Keys
36
    private static function cacheKey()
37
    {
38
        Cache::has('categories') ? Cache::forget('categories') : '';
39
    }
40
41
    // Logs
42
    protected static $logName = 'category';
43
44
    public function getActivitylogOptions(): LogOptions
0 ignored issues
show
Bug introduced by
The type Adminetic\Website\Models\Admin\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...
45
    {
46
        return LogOptions::defaults();
47
    }
48
49
    protected $parentColumn = 'category_id';
50
51
    protected $casts = [
52
        'meta_keywords' => 'array',
53
    ];
54
55
    // Relation
56
    public function categorizable()
57
    {
58
        return $this->morphTo();
59
    }
60
61
    public function parent()
62
    {
63
        return $this->belongsTo(Category::class, $this->parentColumn);
64
    }
65
66
    public function categories()
67
    {
68
        return $this->hasMany(Category::class);
69
    }
70
71
    public function childrenCategories()
72
    {
73
        return $this->hasMany(Category::class)->with('categories');
74
    }
75
76
    // Scopes
77
78
    public function scopePositionCategory($query, $limit = 4)
79
    {
80
        return $query->with('children')->orderBy('position', 'desc')->take($limit);
81
    }
82
83
    public function scopeActive($query)
84
    {
85
        return $query->where('active', 1);
86
    }
87
}
88