Passed
Push — master ( 956624...05ed8c )
by Bertrand
08:49
created

Interact::addInteraction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 3
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
4
namespace App\Src\UseCases\Domain\Context\Model;
5
6
7
use App\Events\InteractionOnPage;
8
9
trait Interact
10
{
11
    public function interaction(array $interactions, int $pageId, array $doneValue = []):Interaction
12
    {
13
        $follow = in_array('follow', $interactions);
14
        $applause = in_array('applause', $interactions);
15
        $done = in_array('done', $interactions);
16
        return new Interaction($pageId, $follow, $applause, $done, $doneValue);
17
    }
18
19
    public function addInteraction(array $interactions, int $pageId, array $doneValue = [])
20
    {
21
        $interaction = $this->interaction($interactions, $pageId, $doneValue);
22
        $this->interactionRepository->save($this, $interaction);
23
        event(new InteractionOnPage($pageId));
24
    }
25
26
    public function updateInteraction(Interaction $interaction, array $newInteractions, array $doneValue = [])
27
    {
28
        $interaction->update($newInteractions, $doneValue);
29
        $this->interactionRepository->save($this, $interaction);
30
        event(new InteractionOnPage($interaction->pageId()));
31
    }
32
}
33