Passed
Push — main ( 93d181...6c645c )
by PRATIK
15:49
created

Software::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
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
use Spatie\SchemaOrg\Schema;
12
use Spatie\SchemaOrg\SoftwareApplication;
13
14
class Software extends Model implements HasMedia
15
{
16
    use LogsActivity, InteractsWithMedia;
17
18
    protected $guarded = [];
19
20
    // Forget cache on updating or saving and deleting
21
    public static function boot()
22
    {
23
        parent::boot();
24
25
        static::saving(function () {
26
            self::cacheKey();
27
        });
28
29
        static::deleting(function () {
30
            self::cacheKey();
31
        });
32
    }
33
34
    // Cache Keys
35
    private static function cacheKey()
36
    {
37
        Cache::has('software') ? Cache::forget('software') : '';
38
    }
39
40
    // Logs
41
    protected static $logName = 'software';
42
43
    public function getActivitylogOptions(): LogOptions
44
    {
45
        return LogOptions::defaults();
46
    }
47
48
    protected $appends = ['banner'];
49
50
    protected $casts = [
51
        'data' => 'array',
52
    ];
53
54
    public function __construct(array $attributes = [])
55
    {
56
        $this->table = config('website.table_prefix', 'website') . '_softwares';
57
58
        parent::__construct($attributes);
59
    }
60
61
62
    // Accessors
63
    public function getBannerAttribute()
64
    {
65
        return !is_null($this->getFirstMedia('banner')) ? $this->getFirstMediaUrl('banner') : logoBanner();
0 ignored issues
show
Bug introduced by
The function logoBanner was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

65
        return !is_null($this->getFirstMedia('banner')) ? $this->getFirstMediaUrl('banner') : /** @scrutinizer ignore-call */ logoBanner();
Loading history...
66
    }
67
68
    // Relationships
69
    public function category()
70
    {
71
        return $this->belongsTo(Category::class);
72
    }
73
74
    public function inquiries()
75
    {
76
        return $this->hasMany(Inquiry::class);
77
    }
78
79
    // Scopes
80
    public function scopePosition($qry)
81
    {
82
        return $qry->orderBy('position');
83
    }
84
85
    public function scopeActive($qry)
86
    {
87
        return $qry->where('active', 1);
88
    }
89
90
    public function scopeFeatured($qry)
91
    {
92
        return $qry->where('featured', 1);
93
    }
94
95
    public function searchSchema()
96
    {
97
        $modules = isset($this->data['modules']) ? $this->data['modules'] : null;
0 ignored issues
show
Bug Best Practice introduced by
The property data does not exist on Adminetic\Website\Models\Admin\Software. Did you maybe forget to declare it?
Loading history...
98
        $schema = Schema::softwareApplication()
99
            ->name($this->meta_name ?? $this->name)
0 ignored issues
show
Bug Best Practice introduced by
The property meta_name does not exist on Adminetic\Website\Models\Admin\Software. Did you maybe forget to declare it?
Loading history...
Bug Best Practice introduced by
The property name does not exist on Adminetic\Website\Models\Admin\Software. Did you maybe forget to declare it?
Loading history...
100
            ->author(title())
0 ignored issues
show
Bug introduced by
The function title was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

100
            ->author(/** @scrutinizer ignore-call */ title())
Loading history...
101
            ->description($this->meta_description ?? $this->excerpt)
0 ignored issues
show
Bug Best Practice introduced by
The property meta_description does not exist on Adminetic\Website\Models\Admin\Software. Did you maybe forget to declare it?
Loading history...
Bug Best Practice introduced by
The property excerpt does not exist on Adminetic\Website\Models\Admin\Software. Did you maybe forget to declare it?
Loading history...
102
            ->image($this->banner)
0 ignored issues
show
Bug Best Practice introduced by
The property banner does not exist on Adminetic\Website\Models\Admin\Software. Did you maybe forget to declare it?
Loading history...
103
            ->if(!is_null($modules), function (SoftwareApplication $schema) use ($modules) {
104
                $schema->email(collect($modules)->pluck('name')->toArray());
105
            })
106
            ->url(route('website.software', ['software' => $this->slug]))
0 ignored issues
show
Bug Best Practice introduced by
The property slug does not exist on Adminetic\Website\Models\Admin\Software. Did you maybe forget to declare it?
Loading history...
107
            ->keywords($this->meta_keywords);
0 ignored issues
show
Bug Best Practice introduced by
The property meta_keywords does not exist on Adminetic\Website\Models\Admin\Software. Did you maybe forget to declare it?
Loading history...
108
109
        return $schema->toScript();
110
    }
111
}
112