Passed
Push — master ( 3e286c...15544c )
by
02:44 queued 10s
created

Item::addMessageAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 2
1
<?php
2
3
/*
4
 * This file is part of the LineMob package.
5
 *
6
 * (c) Ishmael Doss <[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
namespace LineMob\Core\Template\Carousel;
13
14
use LineMob\Core\Template\Action;
15
16
/**
17
 * @author Ishmael Doss <[email protected]>
18
 */
19
class Item
20
{
21
    /**
22
     * @var string
23
     */
24
    public $thumbnail;
25
26
    /**
27
     * @var string
28
     */
29
    public $text;
30
31
    /**
32
     * @var string
33
     */
34
    public $title;
35
36
    /**
37
     * @var Action[]
38
     */
39
    public $actions;
40
41
    public function __construct($title, $text, $thumbnail, array $actions = [])
42
    {
43
        $this->title = $title;
44
        $this->text = $text;
45
        $this->thumbnail = $thumbnail;
46
47
        foreach ($actions as $action) {
48
            if (!$action instanceof Action) {
49
                throw new \InvalidArgumentException("`Action` should be typeof: ".Action::class);
50
            }
51
52
            $this->actions[] = $action;
53
        }
54
    }
55
56
    /**
57
     * @param $label
58
     * @param $text
59
     */
60
    public function addMessageAction($label, $text)
61
    {
62
        $this->actions[] = new Action($label, $text, Action::TYPE_MESSAGE);
63
    }
64
65
    /**
66
     * @param $label
67
     * @param $link
68
     */
69
    public function addUriAction($label, $link)
70
    {
71
        $this->actions[] = new Action($label, $link, Action::TYPE_URI);
72
    }
73
74
    /**
75
     * @param $label
76
     * @param $data
77
     */
78
    public function addPostbackAction($label, $data)
79
    {
80
        $this->actions[] = new Action($label, $data, Action::TYPE_POSTBACK);
81
    }
82
}
83