Passed
Push — main ( 0b35b5...f9c7b3 )
by Tan
02:29
created

LoveScope   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A loveTo() 0 3 1
A lovesTo() 0 3 1
1
<?php
2
3
namespace CSlant\LaravelLike\Traits\Love;
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 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', LikeTypeEnum::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', LikeTypeEnum::LOVE);
39
    }
40
}
41