Completed
Push — master ( 9c0c05...be15ca )
by Anton
09:00
created

DecrementAggregates   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 7
c 1
b 0
f 0
dl 0
loc 25
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 7 1
A __construct() 0 3 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\Reactant\Listeners;
15
16
use Cog\Laravel\Love\Reactant\Jobs\DecrementAggregatesJob;
17
use Cog\Laravel\Love\Reaction\Events\ReactionHasBeenRemoved;
18
use Illuminate\Contracts\Bus\Dispatcher;
19
use Illuminate\Contracts\Queue\ShouldQueue;
20
21
final class DecrementAggregates implements ShouldQueue
22
{
23
    /**
24
     * @var \Illuminate\Contracts\Bus\Dispatcher
25
     */
26
    private $dispatcher;
27
28
    public function __construct(Dispatcher $dispatcher)
29
    {
30
        $this->dispatcher = $dispatcher;
31
    }
32
33
    /**
34
     * Handle the event.
35
     *
36
     * @param  \Cog\Laravel\Love\Reaction\Events\ReactionHasBeenRemoved  $event
37
     * @return void
38
     */
39
    public function handle(ReactionHasBeenRemoved $event): void
40
    {
41
        $reaction = $event->getReaction();
42
        $reactant = $reaction->getReactant();
43
44
        $this->dispatcher->dispatch(
45
            new DecrementAggregatesJob($reactant, $reaction)
46
        );
47
    }
48
}
49