Completed
Push — main ( 407a1d...b509b5 )
by
unknown
17s queued 14s
created

InteractionRelationship   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 30
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A likes() 0 3 1
A likeOne() 0 3 1
A interactionType() 0 3 1
1
<?php
2
3
namespace CSlant\LaravelLike\Traits;
4
5
use CSlant\LaravelLike\Models\Like;
6
use Illuminate\Database\Eloquent\Model;
7
use Illuminate\Database\Eloquent\Relations\MorphMany;
8
use Illuminate\Database\Eloquent\Relations\MorphOne;
9
10
/**
11
 * Trait InteractionRelationship
12
 *
13
 * @package CSlant\LaravelLike\Traits
14
 * @mixin Model
15
 *
16
 * @method MorphOne morphOne(string $related, string $name, string $type = null, string $id = null, string $localKey = null)
17
 * @method MorphMany morphMany(string $related, string $name, string $type = null, string $id = null, string $localKey = null)
18
 */
19
trait InteractionRelationship
20
{
21
    /**
22
     * Like has one relationship with the model.
23
     *
24
     * @return MorphOne
25
     */
26
    public function likeOne(): MorphOne
27
    {
28
        return $this->morphOne(Like::class, 'model');
29
    }
30
31
    /**
32
     * Like has many relationship with the model.
33
     *
34
     * @return MorphMany
35
     */
36
    public function likes(): MorphMany
37
    {
38
        return $this->morphMany(Like::class, 'model');
39
    }
40
41
    /**
42
     * Get the interaction type.
43
     *
44
     * @return string
45
     */
46
    public function interactionType(): string
47
    {
48
        return $this->type->value;
49
    }
50
}
51