Passed
Push — master ( 6bf6cd...d24e2b )
by Anton
04:42 queued 01:52
created

ReactionObserver::creating()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
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
use Illuminate\Contracts\Events\Dispatcher as DispatcherInterface;
20
21
final class ReactionObserver
22
{
23
    private DispatcherInterface $eventDispatcher;
24
25
    public function __construct(
26
        DispatcherInterface $eventDispatcher,
27
    ) {
28
        $this->eventDispatcher = $eventDispatcher;
29
    }
30
31
    public function created(
32
        Reaction $reaction,
33
    ): void {
34
        $this->eventDispatcher->dispatch(
35
            new ReactionHasBeenAdded($reaction),
36
        );
37
    }
38
39
    public function deleted(
40
        Reaction $reaction,
41
    ): void {
42
        $this->eventDispatcher->dispatch(
43
            new ReactionHasBeenRemoved($reaction),
44
        );
45
    }
46
}
47