Passed
Branch main (a1fa3a)
by Tan
02:30
created

LoveScope   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 3
Bugs 1 Features 1
Metric Value
wmc 3
eloc 4
c 3
b 1
f 1
dl 0
loc 32
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A loveTo() 0 3 1
A lovesTo() 0 3 1
A isLovedBy() 0 3 1
1
<?php
2
3
namespace CSlant\LaravelLike\Traits\Love;
4
5
use CSlant\LaravelLike\Enums\InteractionTypeEnum;
6
use Illuminate\Database\Eloquent\Model;
7
use Illuminate\Database\Eloquent\Relations\MorphMany;
8
use Illuminate\Database\Eloquent\Relations\MorphOne;
9
10
/**
11
 * Trait LoveScope
12
 *
13
 * @package CSlant\LaravelLike\Traits\Love
14
 * @mixin Model
15
 *
16
 * @method MorphOne likeOne()
17
 * @method MorphMany likes()
18
 */
19
trait LoveScope
20
{
21
    /**
22
     * The scope locale for select love relationship.
23
     *
24
     * @return MorphOne
25
     */
26
    public function loveTo(): MorphOne
27
    {
28
        return $this->likeOne()->where('type', InteractionTypeEnum::LOVE);
29
    }
30
31
    /**
32
     * The scope locale for select loves relationship.
33
     *
34
     * @return MorphMany
35
     */
36
    public function lovesTo(): MorphMany
37
    {
38
        return $this->likes()->where('type', InteractionTypeEnum::LOVE);
39
    }
40
41
    /**
42
     * Check if the model has been loved by the given user.
43
     *
44
     * @param  int  $userId
45
     *
46
     * @return bool
47
     */
48
    public function isLovedBy(int $userId): bool
49
    {
50
        return $this->isInteractedBy($userId, InteractionTypeEnum::LOVE);
0 ignored issues
show
Bug introduced by
It seems like isInteractedBy() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

50
        return $this->/** @scrutinizer ignore-call */ isInteractedBy($userId, InteractionTypeEnum::LOVE);
Loading history...
51
    }
52
}
53