Completed
Branch develop (a0a623)
by Romain
02:33
created

Button   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 49
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A jsonSerialize() 0 15 1
1
<?php
2
namespace Kerox\Messenger\Message\Attachment\Template;
3
4
use Kerox\Messenger\Message\Attachment\Template;
5
6
class Button extends Template
7
{
8
9
    /**
10
     * @var string
11
     */
12
    protected $text;
13
14
    /**
15
     * @var \Kerox\Messenger\Message\Attachment\Template\Buttons\AbstractButtons[]
16
     */
17
    protected $buttons;
18
19
    /**
20
     * Buttons constructor.
21
     *
22
     * @param string $text
23
     * @param \Kerox\Messenger\Message\Attachment\Template\Buttons\AbstractButtons[] $buttons
24
     */
25
    public function __construct(string $text, array $buttons)
26
    {
27
        parent::__construct();
28
29
        $this->isValidString($text, 320);
30
        $this->isValidArray($buttons, 3);
31
32
        $this->text = $text;
33
        $this->buttons = $buttons;
34
    }
35
36
    /**
37
     * @return array
38
     */
39
    public function jsonSerialize(): array
40
    {
41
        $payload = [
42
            'template_type' => Template::TYPE_BUTTON,
43
            'text' => $this->text,
44
            'buttons' => $this->buttons,
45
        ];
46
47
        $json = parent::jsonSerialize();
48
        $json += [
49
            'payload' => array_filter($payload)
50
        ];
51
52
        return $json;
53
    }
54
}
55