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

IncrementAggregates::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
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 3
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\Reactant\Listeners;
15
16
use Cog\Laravel\Love\Reactant\Jobs\IncrementAggregatesJob;
17
use Cog\Laravel\Love\Reaction\Events\ReactionHasBeenAdded;
18
use Illuminate\Contracts\Bus\Dispatcher;
19
use Illuminate\Contracts\Queue\ShouldQueue;
20
21
final class IncrementAggregates 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\ReactionHasBeenAdded  $event
37
     * @return void
38
     */
39
    public function handle(ReactionHasBeenAdded $event): void
40
    {
41
        $reaction = $event->getReaction();
42
        $reactant = $reaction->getReactant();
43
44
        $this->dispatcher->dispatch(
45
            new IncrementAggregatesJob($reactant, $reaction)
46
        );
47
    }
48
}
49