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

Category::scopePositionCategory()   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 2
dl 0
loc 3
rs 10
c 1
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\Support\Facades\Cache;
7
use Illuminate\Database\Eloquent\Model;
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 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...
10
11
class Category extends Model
12
{
13
    use LogsActivity, Thumbnail, CategoryMorphedByMany;
14
    use Sluggable, SluggableScopeHelpers;
0 ignored issues
show
Bug introduced by
The type Adminetic\Website\Models\Admin\Sluggable 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...
Bug introduced by
The type Adminetic\Website\Models...n\SluggableScopeHelpers 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...
15
16
    protected $guarded = [];
17
18
    // Forget cache on updating or saving and deleting
19
    public static function boot()
20
    {
21
        parent::boot();
22
23
        static::saving(function () {
24
            self::cacheKey();
25
        });
26
27
        static::deleting(function () {
28
            self::cacheKey();
29
        });
30
31
        Category::creating(function ($model) {
32
            $model->position = Category::max('position') + 1;
33
        });
34
    }
35
36
    // Cache Keys
37
    private static function cacheKey()
38
    {
39
        Cache::has('categories') ? Cache::forget('categories') : '';
40
    }
41
42
    // Logs
43
    protected static $logName = 'category';
44
45
    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...
46
    {
47
        return LogOptions::defaults();
48
    }
49
50
    protected $parentColumn = 'category_id';
51
52
53
    protected $casts = [
54
        'meta_keywords' => 'array'
55
    ];
56
57
    /**
58
     * Return the sluggable configuration array for this model.
59
     *
60
     * @return array
61
     */
62
    public function sluggable(): array
63
    {
64
        return [
65
            'slug' => [
66
                'source' => 'name'
67
            ]
68
        ];
69
    }
70
71
72
    // Relation
73
    public function categorizable()
74
    {
75
        return $this->morphTo();
76
    }
77
78
    public function parent()
79
    {
80
        return $this->belongsTo(Category::class, $this->parentColumn);
81
    }
82
83
    public function categories()
84
    {
85
        return $this->hasMany(Category::class);
86
    }
87
88
    public function childrenCategories()
89
    {
90
        return $this->hasMany(Category::class)->with('categories');
91
    }
92
93
    // Scopes
94
95
    public function scopePositionCategory($query, $limit = 4)
96
    {
97
        return $query->with('children')->orderBy('position', 'desc')->take($limit);
98
    }
99
    public function scopeActive($query)
100
    {
101
        return $query->where('active', 1);
102
    }
103
}
104