Completed
Push — master ( 33476c...427ebd )
by Bertrand
09:14
created

Interaction::update()   B

Complexity

Conditions 8
Paths 8

Size

Total Lines 24
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 8
eloc 22
c 1
b 0
f 0
nc 8
nop 2
dl 0
loc 24
rs 8.4444
1
<?php
2
3
4
namespace App\Src\UseCases\Domain\Agricultural\Model;
5
6
class Interaction
7
{
8
    private $follow;
9
    private $applause;
10
    private $done;
11
    private $pageId;
12
    private $doneValue;
13
14
    public function __construct(
15
        int $pageId,
16
        bool $follow,
17
        bool $applause,
18
        bool $done,
19
        array $doneValue = []
20
    )
21
    {
22
        $this->pageId = $pageId;
23
        $this->done = $done;
24
        $this->follow = $follow;
25
        $this->applause = $applause;
26
        $this->doneValue = $doneValue;
27
    }
28
29
    public function pageId():int
30
    {
31
        return $this->pageId;
32
    }
33
34
    public function update(array $interactions, array $doneValue = [])
35
    {
36
        foreach ($interactions as $interaction){
37
            switch ($interaction){
38
                case 'follow':
39
                    $this->follow = true;
40
                    break;
41
                case 'unfollow':
42
                    $this->follow = false;
43
                    break;
44
                case 'done':
45
                    $this->done = true;
46
                    $this->doneValue = $doneValue;
47
                    break;
48
                case 'undone':
49
                    $this->done = false;
50
                    $this->doneValue = null;
51
                    break;
52
                case 'applause':
53
                    $this->applause = true;
54
                    break;
55
                case 'unapplause':
56
                    $this->applause = false;
57
                    break;
58
            }
59
        }
60
    }
61
62
    public function toArray():array
63
    {
64
        return [
65
            'done' => $this->done,
66
            'follow' => $this->follow,
67
            'applause' => $this->applause,
68
            'value' => $this->doneValue,
69
            'page_id' => $this->pageId
70
        ];
71
    }
72
}
73