Passed
Pull Request — master (#16)
by
unknown
02:52
created

CarouselTemplate::createItemActions()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.2
c 0
b 0
f 0
cc 4
eloc 12
nc 4
nop 1
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
13
namespace LineMob\Core\Template\Carousel;
14
15
use LINE\LINEBot\MessageBuilder\TemplateBuilder\CarouselColumnTemplateBuilder;
16
use LINE\LINEBot\MessageBuilder\TemplateBuilder\CarouselTemplateBuilder;
17
use LINE\LINEBot\MessageBuilder\TemplateMessageBuilder;
18
use LineMob\Core\Template\AbstractTemplate;
19
use LineMob\Core\Template\Action;
20
use LineMob\Core\Template\ActionTemplateTrait;
21
22
/**
23
 * @author Ishmael Doss <[email protected]>
24
 */
25
class CarouselTemplate extends AbstractTemplate
26
{
27
    use ActionTemplateTrait;
28
29
    /**
30
     * @var Item[]
31
     */
32
    public $items;
33
34
    /**
35
     * @var string
36
     */
37
    public $altText = 'This is carousel template.';
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function getTemplate()
43
    {
44
        $items = [];
45
46
        foreach ($this->items as $item) {
47
            $items[] = new CarouselColumnTemplateBuilder(
48
                mb_substr($item->title, 0, 40), mb_substr($item->text, 0, 60),
49
                $item->thumbnail,
50
                $this->createActions($item->actions)
51
            );
52
        }
53
54
        return new TemplateMessageBuilder($this->altText, new CarouselTemplateBuilder($items));
55
    }
56
57
    /**
58
     * @param string $title
59
     * @param string $text
60
     * @param string $thumbnail
61
     * @param array|Action[] $actions
62
     */
63
    public function addItem($title, $text, $thumbnail, array $actions = [])
64
    {
65
        $this->items[] = new Item($title, $text, $thumbnail, $actions);
66
    }
67
}
68