Passed
Push — main ( 4ad008...e9819d )
by Tan
02:45 queued 14s
created

LikeScopes::likes()   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
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace CSlant\LaravelLike\Traits;
4
5
use CSlant\LaravelLike\Enums\LikeTypeEnum;
6
use Illuminate\Database\Eloquent\Model;
7
use Illuminate\Database\Eloquent\Relations\MorphMany;
8
use Illuminate\Database\Eloquent\Relations\MorphOne;
9
10
/**
11
 * Trait LikeScopes
12
 *
13
 * @package CSlant\LaravelLike\Traits
14
 * @mixin Model
15
 */
16
trait LikeScopes
17
{
18
    /**
19
     * The scope locale for select like relationship.
20
     *
21
     * @return MorphOne
22
     */
23
    public function likeTo(): MorphOne
24
    {
25
        return $this->likeOne()->where('type', LikeTypeEnum::LIKE);
0 ignored issues
show
Bug introduced by
It seems like likeOne() 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

25
        return $this->/** @scrutinizer ignore-call */ likeOne()->where('type', LikeTypeEnum::LIKE);
Loading history...
26
    }
27
28
    /**
29
     * The scope locale for select dislike relationship.
30
     *
31
     * @return MorphOne
32
     */
33
    public function dislikeTo(): MorphOne
34
    {
35
        return $this->likeOne()->where('type', LikeTypeEnum::DISLIKE);
36
    }
37
38
    /**
39
     * The scope locale for select likes relationship.
40
     *
41
     * @return MorphMany
42
     */
43
    public function likesTo(): MorphMany
44
    {
45
        return $this->likes()->where('type', LikeTypeEnum::LIKE);
0 ignored issues
show
Bug introduced by
The method likes() does not exist on CSlant\LaravelLike\Traits\LikeScopes. Did you maybe mean likesTo()? ( Ignorable by Annotation )

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

45
        return $this->/** @scrutinizer ignore-call */ likes()->where('type', LikeTypeEnum::LIKE);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
46
    }
47
48
    /**
49
     * The scope locale for select dislikes relationship.
50
     *
51
     * @return MorphMany
52
     */
53
    public function dislikesTo(): MorphMany
54
    {
55
        return $this->likes()->where('type', LikeTypeEnum::DISLIKE);
56
    }
57
58
    /**
59
     * The scope locale for select loves relationship.
60
     *
61
     * @return MorphMany
62
     */
63
    public function lovesTo(): MorphMany
64
    {
65
        return $this->likes()->where('type', LikeTypeEnum::LOVE);
66
    }
67
}
68