Completed
Push — master ( 49518f...3dd743 )
by Karl
10s
created

User   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 84.21%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 4
dl 0
loc 95
ccs 16
cts 19
cp 0.8421
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 8 1
A searches() 0 4 1
A tokens() 0 4 1
A scopeConfirmed() 0 4 1
A scopeUnconfirmed() 0 4 1
A getMaxSearchesAttribute() 0 4 1
A notifications() 0 5 1
1
<?php namespace JobApis\JobsToMail\Models;
2
3
use Illuminate\Database\Eloquent\Model;
4
use Illuminate\Database\Eloquent\SoftDeletes;
5
use Illuminate\Notifications\Notifiable;
6
use Ramsey\Uuid\Uuid;
7
8
class User extends Model
9
{
10
    use Notifiable, SoftDeletes;
11
12
    /**
13
     * Indicates that the IDs are not auto-incrementing.
14
     *
15
     * @var bool
16
     */
17
    public $incrementing = false;
18
19
    /**
20
     * The attributes that are mass assignable.
21
     *
22
     * @var array
23
     */
24
    protected $fillable = [
25
        'email',
26
    ];
27
28
    /**
29
     * Boot function from laravel.
30
     */
31 15
    protected static function boot()
32
    {
33 15
        parent::boot();
34
35 15
        static::creating(function ($model) {
36 2
            $model->{$model->getKeyName()} = Uuid::uuid4();
37 15
        });
38 15
    }
39
40
    /**
41
     * Gets the user's maximum number of allowed searches
42
     *
43
     * @return int
44
     */
45 2
    public function getMaxSearchesAttribute($value): int
46
    {
47 2
        return $value ?? (int) config('app.max_searches');
48
    }
49
50
    /**
51
     * Defines the relationship to Search model
52
     *
53
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
54
     */
55 1
    public function searches()
56
    {
57 1
        return $this->hasMany(Search::class);
58
    }
59
60
    /**
61
     * Defines the relationship to Token model
62
     *
63
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
64
     */
65 2
    public function tokens()
66
    {
67 2
        return $this->hasMany(Token::class);
68
    }
69
70
    /**
71
     * Limits query to "confirmed" users
72
     *
73
     * @return \Illuminate\Database\Eloquent\Builder
74
     */
75 2
    public function scopeConfirmed($query)
76
    {
77 2
        return $query->whereNotNull('confirmed_at');
78
    }
79
80
    /**
81
     * Limits query to "unconfirmed" users
82
     *
83
     * @param $query \Illuminate\Database\Eloquent\Builder
84
     *
85
     * @return \Illuminate\Database\Eloquent\Builder
86
     */
87 1
    public function scopeUnconfirmed($query)
88
    {
89 1
        return $query->whereNull('confirmed_at');
90
    }
91
92
    /**
93
     * Defines the relationship to Notification model
94
     *
95
     * @return \Illuminate\Database\Eloquent\Relations\MorphMany
96
     */
97
    public function notifications()
98
    {
99
        return $this->morphMany(CustomDatabaseNotification::class, 'notifiable')
100
            ->orderBy('created_at', 'desc');
101
    }
102
}
103