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

Keyboard   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 53
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A addButton() 0 6 1
A getButtons() 0 4 1
A toArray() 0 6 1
A jsonSerialize() 0 4 1
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