Completed
Push — master ( 44dea0...59b9fb )
by Vladimir
02:47
created

Keyboard::addButton()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
ccs 3
cts 3
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Templates;
6
7
use FondBot\Contracts\Template;
8
use FondBot\Templates\Keyboard\Button;
9
10
class Keyboard implements Template
11
{
12
    /** @var Button[] */
13
    private $buttons;
14
15
    /**
16
     * Add button.
17
     *
18
     * @param Button $button
19
     *
20
     * @return Keyboard
21
     */
22 1
    public function addButton(Button $button): Keyboard
23
    {
24 1
        $this->buttons[] = $button;
25
26 1
        return $this;
27
    }
28
29
    /**
30
     * Get buttons.
31
     *
32
     * @return Button[]
33
     */
34 1
    public function getButtons(): array
35
    {
36 1
        return $this->buttons;
37
    }
38
39
    /**
40
     * Get the instance as an array.
41
     *
42
     * @return array
43
     */
44 1
    public function toArray(): array
45
    {
46
        return [
47 1
            'buttons' => $this->buttons,
48
        ];
49
    }
50
51
    /**
52
     * Specify data which should be serialized to JSON.
53
     * @link  http://php.net/manual/en/jsonserializable.jsonserialize.php
54
     * @return mixed data which can be serialized by <b>json_encode</b>,
55
     * which is a value of any type other than a resource.
56
     * @since 5.4.0
57
     */
58 1
    public function jsonSerialize(): array
59
    {
60 1
        return $this->toArray();
61
    }
62
}
63