Completed
Push — master ( f2ddff...f08741 )
by Anton
02:57
created

DecrementReactionAggregatesJob::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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\Jobs;
15
16
use Cog\Contracts\Love\Reactant\Models\Reactant as ReactantContract;
17
use Cog\Contracts\Love\Reaction\Models\Reaction as ReactionContract;
18
use Cog\Laravel\Love\Reactant\ReactionCounter\Services\ReactionCounterService;
19
use Cog\Laravel\Love\Reactant\ReactionTotal\Services\ReactionTotalService;
20
use Illuminate\Bus\Queueable;
21
use Illuminate\Contracts\Queue\ShouldQueue;
22
use Illuminate\Foundation\Bus\Dispatchable;
23
24
final class DecrementReactionAggregatesJob implements
25
    ShouldQueue
26
{
27
    use Dispatchable;
28
    use Queueable;
29
30
    /**
31
     * @var \Cog\Contracts\Love\Reactant\Models\Reactant
32
     */
33
    private $reactant;
34
35
    /**
36
     * @var \Cog\Contracts\Love\Reaction\Models\Reaction
37
     */
38
    private $reaction;
39
40
    /**
41
     * @param \Cog\Contracts\Love\Reactant\Models\Reactant $reactant
42
     * @param \Cog\Contracts\Love\Reaction\Models\Reaction $reaction
43
     */
44
    public function __construct(
45
        ReactantContract $reactant,
46
        ReactionContract $reaction
47
    ) {
48
        $this->reactant = $reactant;
49
        $this->reaction = $reaction;
50
    }
51
52
    public function handle(): void
53
    {
54
        (new ReactionCounterService($this->reactant))
55
            ->removeReaction($this->reaction);
56
57
        (new ReactionTotalService($this->reactant))
58
            ->removeReaction($this->reaction);
59
    }
60
}
61