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

Career::__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\SchemaOrg\Schema;
10
11
class Career extends Model
12
{
13
    use LogsActivity;
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
31
    // Cache Keys
32
    private static function cacheKey()
33
    {
34
        Cache::has('careers') ? Cache::forget('careers') : '';
35
        Cache::has('latest_careers') ? Cache::forget('latest_careers') : '';
36
    }
37
38
    // Logs
39
    protected static $logName = 'career';
40
41
    public function getActivitylogOptions(): LogOptions
42
    {
43
        return LogOptions::defaults();
44
    }
45
46
47
    public function __construct(array $attributes = [])
48
    {
49
        $this->table = config('website.table_prefix', 'website') . '_careers';
50
51
        parent::__construct($attributes);
52
    }
53
54
    // Appends
55
    protected $casts = [
56
        'summary' => 'array',
57
    ];
58
59
    // Relationship
60
    public function applications()
61
    {
62
        return $this->hasMany(Application::class);
63
    }
64
65
    // Accessors
66
    public function getGroupAttribute($attribute)
67
    {
68
        return !is_null($attribute) ? (config('website.career_group', [
69
            1 => 'REASEARCHERS/STAFF',
70
            2 => 'FIELD STAFF',
71
            3 => 'INTERN/VOLUNTEERS',
72
        ])[$attribute]) : null;
73
    }
74
75
    // Methods
76
    public function shortListed()
77
    {
78
        return Application::where('career_id', $this->id)->where('short_listed', 1)->latest()->get();
79
    }
80
81
    // Methods
82
    public function selected()
83
    {
84
        return Application::where('career_id', $this->id)->where('selected', 1)->latest()->get();
85
    }
86
87
    public function searchSchema()
88
    {
89
        $schema = Schema::jobPosting()
90
            ->title($this->name)
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist on Adminetic\Website\Models\Admin\Career. Did you maybe forget to declare it?
Loading history...
91
            ->name($this->name)
92
            ->url(route('website.career', ['career' => $this->slug]))
0 ignored issues
show
Bug Best Practice introduced by
The property slug does not exist on Adminetic\Website\Models\Admin\Career. Did you maybe forget to declare it?
Loading history...
93
            ->alternateName($this->designation)
0 ignored issues
show
Bug Best Practice introduced by
The property designation does not exist on Adminetic\Website\Models\Admin\Career. Did you maybe forget to declare it?
Loading history...
94
            ->jobLocation($this->location)
0 ignored issues
show
Bug Best Practice introduced by
The property location does not exist on Adminetic\Website\Models\Admin\Career. Did you maybe forget to declare it?
Loading history...
95
            ->baseSalary($this->salary)
0 ignored issues
show
Bug Best Practice introduced by
The property salary does not exist on Adminetic\Website\Models\Admin\Career. Did you maybe forget to declare it?
Loading history...
96
            ->datePosted($this->created_at)
97
            ->description($this->excerpt)
0 ignored issues
show
Bug Best Practice introduced by
The property excerpt does not exist on Adminetic\Website\Models\Admin\Career. Did you maybe forget to declare it?
Loading history...
98
            ->directApply(true)
99
            ->estimatedSalary($this->salary)
100
            ->occupationalCategory(config('website.career_group')[$this->group ?? 1]);
0 ignored issues
show
Bug Best Practice introduced by
The property group does not exist on Adminetic\Website\Models\Admin\Career. Did you maybe forget to declare it?
Loading history...
101
102
        return $schema->toScript();
103
    }
104
}
105