Passed
Push — master ( ab9b9c...1f35b0 )
by
02:28
created

ActionTemplateTrait::getTemplate()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 18
rs 9.2
c 1
b 0
f 0
cc 4
eloc 12
nc 4
nop 0
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;
13
14
use LINE\LINEBot\MessageBuilder\TemplateBuilder\ConfirmTemplateBuilder;
15
use LINE\LINEBot\MessageBuilder\TemplateMessageBuilder;
16
use LINE\LINEBot\TemplateActionBuilder\MessageTemplateActionBuilder;
17
use LINE\LINEBot\TemplateActionBuilder\PostbackTemplateActionBuilder;
18
use LINE\LINEBot\TemplateActionBuilder\UriTemplateActionBuilder;
19
20
/**
21
 * @author Ishmael Doss <[email protected]>
22
 *
23
 * @property array actions
24
 * @property string altText
25
 * @property string title
26
 */
27
trait ActionTemplateTrait
28
{
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function getTemplate()
34
    {
35
        $actions = [];
36
37
        foreach ($this->actions as $action) {
38
            switch (strtolower($action->type)) {
39
                case Action::TYPE_POSTBACK:
40
                    $actions[] = new PostbackTemplateActionBuilder($action->label, $action->value);
41
                    break;
42
                case Action::TYPE_URI:
43
                    $actions[] = new UriTemplateActionBuilder($action->label, $action->value);
44
                    break;
45
                default:
46
                    $actions[] = new MessageTemplateActionBuilder($action->label, $action->value);;
47
            }
48
        }
49
50
        return new TemplateMessageBuilder($this->altText, new ConfirmTemplateBuilder($this->title, $actions));
51
    }
52
}
53