Passed
Branch main (a1fa3a)
by Tan
05:18
created

LoveScope::isLovedBy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 1
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
nc 1
nop 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