LikeCount::likesCountDigital()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace CSlant\LaravelLike\Traits\Like;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Eloquent\Relations\MorphMany;
7
8
/**
9
 * Trait LikeCount
10
 *
11
 * @package CSlant\LaravelLike\Traits\Like
12
 * @mixin Model
13
 *
14
 * @method MorphMany<self, *> likesTo()
15
 * @method MorphMany<self, *> dislikesTo()
16
 */
17
trait LikeCount
18
{
19
    /**
20
     * Get the count of likes.
21
     *
22
     * @return int
23
     */
24
    public function likesCount(): int
25
    {
26
        return $this->likesTo()->count();
27
    }
28
29
    /**
30
     * Get the count of dislikes.
31
     *
32
     * @return int
33
     */
34
    public function dislikesCount(): int
35
    {
36
        return $this->dislikesTo()->count();
37
    }
38
39
    /**
40
     * Get the count of likes in digital format.
41
     *
42
     * @return string
43
     */
44
    public function likesCountDigital(): string
45
    {
46
        return count_digital($this->likesCount());
47
    }
48
49
    /**
50
     * Get the count of dislikes in digital format.
51
     *
52
     * @return string
53
     */
54
    public function dislikesCountDigital(): string
55
    {
56
        return count_digital($this->dislikesCount());
57
    }
58
}
59