Completed
Pull Request — master (#91)
by Anton
04:55 queued 44s
created

ReactionObserver   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A deleted() 0 4 1
A created() 0 4 1
A creating() 0 5 2
1
<?php
2
3
/*
4
 * This file is part of Laravel Love.
5
 *
6
 * (c) Anton Komarev <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Cog\Laravel\Love\Reaction\Observers;
15
16
use Cog\Laravel\Love\Reaction\Events\ReactionHasBeenAdded;
17
use Cog\Laravel\Love\Reaction\Events\ReactionHasBeenRemoved;
18
use Cog\Laravel\Love\Reaction\Models\Reaction;
19
20
final class ReactionObserver
21
{
22
    public function creating(
23
        Reaction $reaction
24
    ): void {
25
        if (is_null($reaction->getAttributeValue('rate'))) {
26
            $reaction->setAttribute('rate', Reaction::DEFAULT_RATE);
27
        }
28
    }
29
30
    public function created(
31
        Reaction $reaction
32
    ): void {
33
        event(new ReactionHasBeenAdded($reaction));
34
    }
35
36
    public function deleted(
37
        Reaction $reaction
38
    ): void {
39
        event(new ReactionHasBeenRemoved($reaction));
40
    }
41
}
42