Completed
Pull Request — master (#33)
by Karl
02:24
created

User   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 58.81%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 4
dl 0
loc 84
rs 10
c 0
b 0
f 0
ccs 10
cts 17
cp 0.5881

6 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 8 1
A scopeConfirmed() 0 4 1
A scopeUnconfirmed() 0 4 1
A searches() 0 4 1
A tokens() 0 4 1
A notifications() 0 6 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 12
    protected static function boot()
32
    {
33 12
        parent::boot();
34
35 12
        static::creating(function ($model) {
36 2
            $model->{$model->getKeyName()} = Uuid::uuid4();
37 12
        });
38 12
    }
39
40
    /**
41
     * Defines the relationship to Search model
42
     *
43
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
44
     */
45
    public function searches()
46
    {
47
        return $this->hasMany(Search::class);
48
    }
49
50
    /**
51
     * Defines the relationship to Token model
52
     *
53
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
54
     */
55
    public function tokens()
56
    {
57
        return $this->hasMany(Token::class);
58
    }
59
60
    /**
61
     * Limits query to "confirmed" users
62
     *
63
     * @return \Illuminate\Database\Eloquent\Builder
64
     */
65 2
    public function scopeConfirmed($query)
66
    {
67 2
        return $query->whereNotNull('confirmed_at');
68
    }
69
70
    /**
71
     * Limits query to "unconfirmed" users
72
     *
73
     * @param $query \Illuminate\Database\Eloquent\Builder
74
     *
75
     * @return \Illuminate\Database\Eloquent\Builder
76
     */
77 1
    public function scopeUnconfirmed($query)
78
    {
79 1
        return $query->whereNull('confirmed_at');
80
    }
81
82
    /**
83
     * Get the entity's notifications.
84
     */
85
    public function notifications()
86
    {
87
        // Overriding the normal Database Notification model here
88
        return $this->morphMany(CustomDatabaseNotification::class, 'notifiable')
89
            ->orderBy('created_at', 'desc');
90
    }
91
}
92