Passed
Push — master ( c05883...1d5c29 )
by Nikolay
02:30
created

ReplyKeyboardMarkupType   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 71
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 9 2
A addKeyboardButton() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TgBotApi\BotApiBase\Type;
6
7
use TgBotApi\BotApiBase\Method\Traits\FillFromArrayTrait;
8
9
/**
10
 * Class ReplyKeyboardMarkupType.
11
 *
12
 * @see https://core.telegram.org/bots/api#replykeyboardmarkup
13
 * @see https://core.telegram.org/bots#keyboards
14
 */
15
class ReplyKeyboardMarkupType
16
{
17
    use FillFromArrayTrait;
18
19
    /**
20
     * Array of button rows, each represented by an Array of KeyboardButton objects.
21
     *
22
     * @var KeyboardButtonType[][]
23
     */
24
    public $keyboard;
25
26
    /**
27
     * Optional. Requests clients to resize the keyboard vertically for optimal fit (e.g., make the keyboard smaller
28
     * if there are just two rows of buttons). Defaults to false, in which case the custom keyboard is always
29
     * of the same height as the app's standard keyboard.
30
     *
31
     * @var bool|null
32
     */
33
    public $resizeKeyboard;
34
35
    /**
36
     * Optional. Requests clients to hide the keyboard as soon as it's been used. The keyboard will still be available,
37
     * but clients will automatically display the usual letter-keyboard in the chat – the user can press a special
38
     * button in the input field to see the custom keyboard again. Defaults to false.
39
     *
40
     * @var bool|null
41
     */
42
    public $oneTimeKeyboard;
43
44
    /**
45
     * Optional. Use this parameter if you want to show the keyboard to specific users only. Targets: 1) users
46
     * that are @mentioned in the text of the MessageType object;
47
     * 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message.
48
     *
49
     * Example: A user requests to change the bot‘s language, bot replies to the request with a keyboard to
50
     * select the new language. Other users in the group don’t see the keyboard.
51
     *
52
     * @var bool|null
53
     */
54
    public $selective;
55
56
    /**
57
     * @param KeyboardButtonType[][] $keyboard
58
     * @param array|null             $data
59
     *
60
     * @throws \TgBotApi\BotApiBase\Exception\BadArgumentException
61
     *
62
     * @return ReplyKeyboardMarkupType
63
     */
64
    public static function create(array $keyboard, array $data = null): ReplyKeyboardMarkupType
65
    {
66
        $instance = new static();
67
        $instance->keyboard = $keyboard;
68
        if ($data) {
69
            $instance->fill($data);
70
        }
71
72
        return $instance;
73
    }
74
75
    /**
76
     * @param int                $index  keyboard row
77
     * @param KeyboardButtonType $button
78
     *
79
     * @return ReplyKeyboardMarkupType
80
     */
81
    public function addKeyboardButton(int $index, KeyboardButtonType $button): ReplyKeyboardMarkupType
82
    {
83
        $this->keyboard[$index][] = $button;
84
85
        return $this;
86
    }
87
}
88