Completed
Push — main ( 628b81...8dfba4 )
by PRATIK
03:45 queued 03:43
created

Project::getIconImageAttribute()   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
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 3
rs 10
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 Project extends Model implements HasMedia
13
{
14
    use LogsActivity, InteractsWithMedia;
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
32
    // Cache Keys
33
    private static function cacheKey()
34
    {
35
        Cache::has('projects') ? Cache::forget('projects') : '';
36
    }
37
38
    // Logs
39
    protected static $logName = 'project';
40
41
    public function getActivitylogOptions(): LogOptions
42
    {
43
        return LogOptions::defaults();
44
    }
45
46
    protected $casts = [
47
        'data' => 'array',
48
    ];
49
50
    // Relationships
51
    public function category()
52
    {
53
        return $this->belongsTo(Category::class);
54
    }
55
56
    // Scopes
57
    public function scopePosition($qry)
58
    {
59
        return $qry->orderBy('position');
60
    }
61
62
    public function scopeActive($qry)
63
    {
64
        return $qry->where('active', 1);
65
    }
66
67
    public function scopeFeatured($qry)
68
    {
69
        return $qry->where('featured', 1);
70
    }
71
72
    // Attribute
73
    public function getStatusAttribute($attribute)
74
    {
75
        return in_array($attribute, [1, 2, 3]) ?
76
            [
77
                1 => 'Ongoing',
78
                2 => 'Not Started',
79
                3 => 'Finished',
80
            ][$attribute] : null;
81
    }
82
83
     // Accessors
84
    public function getImageAttribute()
85
    {
86
        return !is_null($this->getFirstMedia('image')) ? $this->getFirstMediaUrl('image') : asset('adminetic/static/placeholder.jpg');
87
    }
88
89
    public function getIconImageAttribute()
90
    {
91
        return !is_null($this->getFirstMedia('icon_image')) ? $this->getFirstMediaUrl('icon_image') : asset('adminetic/static/placeholder.jpg');
92
    }
93
}
94