Passed
Push — main ( 6ab830...898592 )
by Tan
02:27
created

HasLove   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A lovesCount() 0 3 1
A lovesCountDigital() 0 3 1
1
<?php
2
3
namespace CSlant\LaravelLike;
4
5
use CSlant\LaravelLike\Traits\Love\LoveScope;
6
use Illuminate\Database\Eloquent\Model;
7
use Illuminate\Database\Eloquent\Relations\MorphMany;
8
use Illuminate\Database\Eloquent\Relations\MorphOne;
9
10
/**
11
 * Trait HasLove
12
 *
13
 * @package CSlant\LaravelLike
14
 * @mixin Model
15
 *
16
 * @method MorphOne likeOne()
17
 * @method MorphMany likes()
18
 */
19
trait HasLove
20
{
21
    use LoveScope;
22
23
    /**
24
     * Get the count of loves.
25
     *
26
     * @return int
27
     */
28
    public function lovesCount(): int
29
    {
30
        return $this->lovesTo()->count();
31
    }
32
33
    /**
34
     * Get the count of loves in digital format.
35
     *
36
     * @return string
37
     */
38
    public function lovesCountDigital(): string
39
    {
40
        return count_digital($this->lovesCount());
41
    }
42
}
43