Contact   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 45
ccs 0
cts 6
cp 0
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A scopeForUser() 0 3 1
A source() 0 3 1
A user() 0 3 1
1
<?php
2
3
namespace App\Models;
4
5
use App\Traits\HasUUID;
6
use Illuminate\Database\Eloquent\Factories\HasFactory;
7
use Illuminate\Database\Eloquent\Model;
8
use Illuminate\Database\Eloquent\Relations\MorphTo;
9
10
class Contact extends Model
11
{
12
    use HasFactory;
13
    use HasUUID;
14
15
    /**
16
     * The attributes that are mass assignable.
17
     *
18
     * @var array
19
     */
20
    protected $fillable = [
21
        'name',
22
        'user_id',
23
        'source_type',
24
        'source_id',
25
    ];
26
27
    /**
28
     * Scope a query to only include active users.
29
     *
30
     * @param  \Illuminate\Database\Eloquent\Builder  $query
31
     * @param  string  $user_id
32
     * @return \Illuminate\Database\Eloquent\Builder
33
     */
34
    public function scopeForUser($query, $user_id)
35
    {
36
        return $query->where('user_id', $user_id);
37
    }
38
39
    /**
40
     * Get the user that owns the contact.
41
     */
42
    public function user()
43
    {
44
        return $this->belongsTo(User::class);
45
    }
46
47
    /**
48
     * Get the owner model of the contact.
49
     *
50
     * @return \Illuminate\Database\Eloquent\Relations\MorphTo
51
     */
52
    public function source(): MorphTo
53
    {
54
        return $this->morphTo('source', 'source_type', 'source_id', 'id');
55
    }
56
}
57