Passed
Pull Request — master (#91)
by Anton
02:43
created

ReactionObserver::creating()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 5
rs 10
cc 2
nc 2
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::RATE_DEFAULT);
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