ModelObserver   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A deleted() 0 7 2
A removeLikesOnDelete() 0 3 2
1
<?php
2
3
namespace Turahe\Likeable\Observers;
4
5
use Turahe\Likeable\Contracts\Likeable as LikeableContract;
6
7
/**
8
 * Class ModelObserver.
9
 */
10
class ModelObserver
11
{
12
    /**
13
     * Handle the deleted event for the model.
14
     *
15
     * @param \Turahe\Likeable\Contracts\Likeable $likeable
16
     * @return void
17
     */
18
    public function deleted(LikeableContract $likeable)
19
    {
20
        if (! $this->removeLikesOnDelete($likeable)) {
21
            return;
22
        }
23
24
        $likeable->removeLikes();
25
    }
26
27
    /**
28
     * Should remove likes on model delete (defaults to true).
29
     *
30
     * @param \Turahe\Likeable\Contracts\Likeable $likeable
31
     * @return bool
32
     */
33
    protected function removeLikesOnDelete(LikeableContract $likeable)
34
    {
35
        return isset($likeable->removeLikesOnDelete) ? $likeable->removeLikesOnDelete : true;
0 ignored issues
show
Bug introduced by
Accessing removeLikesOnDelete on the interface Turahe\Likeable\Contracts\Likeable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
36
    }
37
}
38