Completed
Pull Request — master (#91)
by Anton
02:42
created

ReactionObserver::created()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 1
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