Reactable   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 24
c 0
b 0
f 0
wmc 2
lcom 0
cbo 2
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A reactions() 0 6 1
A getReactionsSummary() 0 8 1
1
<?php
2
3
namespace FrancescoMalatesta\LaravelReactions\Traits;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Eloquent\Relations\MorphToMany;
7
8
trait Reactable
9
{
10
    /**
11
     * @return MorphToMany
12
     */
13
    public function reactions()
14
    {
15
        /** @var $this Model */
16
        return $this->morphToMany('FrancescoMalatesta\\LaravelReactions\\Models\\Reaction', 'reactable')
17
            ->withPivot(['responder_id', 'responder_type']);
18
    }
19
20
    /**
21
     * @return \Illuminate\Database\Eloquent\Collection|static[]
22
     */
23
    public function getReactionsSummary()
24
    {
25
        return $this->reactions()
26
            ->getQuery()
27
            ->select('name', \DB::raw('count(*) as count'))
28
            ->groupBy('name')
29
            ->get();
30
    }
31
}
32