TextTemplate   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 3
c 2
b 1
f 1
dl 0
loc 37
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getTemplate() 0 17 3
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\TextMessageBuilder;
15
16
/**
17
 * @author Ishmael Doss <[email protected]>
18
 */
19
class TextTemplate extends AbstractTemplate
20
{
21
    /**
22
     * @var string
23
     */
24
    public $text;
25
26
    /**
27
     * @var string
28
     */
29
    public $emoticon;
30
31
    /**
32
     * @var string[]
33
     */
34
    public $extra = [];
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function getTemplate()
40
    {
41
        $text = $this->text;
42
43
        if ($this->emoticon) {
44
            $emoticon = substr($this->emoticon, 2);
45
46
            if (!$emoticon = @hex2bin(str_repeat('0', 8 - strlen($emoticon)).$emoticon)) {
47
                throw new \RuntimeException('hex2bin(): Input string must be hexadecimal string. see - https://devdocs.line.me/files/emoticon.pdf');
48
            }
49
50
            $emoticon = mb_convert_encoding($emoticon, 'UTF-8', 'UTF-32BE');
51
52
            $text = sprintf("%s %s", $emoticon, $this->text);
53
        }
54
55
        return new TextMessageBuilder($text, ...$this->extra);
56
    }
57
}
58