KeyboardButtonType   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 12
c 0
b 0
f 0
dl 0
loc 56
rs 10
ccs 6
cts 6
cp 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TgBotApi\BotApiBase\Type;
6
7
use TgBotApi\BotApiBase\Exception\BadArgumentException;
8
use TgBotApi\BotApiBase\Method\Traits\FillFromArrayTrait;
9
use TgBotApi\BotApiBase\Type\Poll\KeyboardButtonPollType;
10
11
/**
12
 * Class KeyboardButtonType
13
 * Note: request_contact and request_location options will only work in Telegram versions released after 9
14
 * April, 2016. Older clients will ignore them.
15
 *
16
 * @see https://core.telegram.org/bots/api#keyboardbutton
17
 */
18
class KeyboardButtonType
19
{
20
    use FillFromArrayTrait;
21
22
    /**
23
     * Text of the button. If none of the optional fields are used,
24
     * it will be sent as a message when the button is pressed.
25
     *
26
     * @var string
27
     */
28
    public $text;
29
30
    /**
31
     * Optional. If True, the user's phone number will be sent as a contact when the button is pressed.
32
     * Available in private chats only.
33
     *
34
     * @var bool|null
35
     */
36
    public $requestContact;
37
38
    /**
39
     * Optional. If True, the user's current location will be sent when the button is pressed.
40
     * Available in private chats only.
41
     *
42
     * @var bool|null
43
     */
44
    public $requestLocation;
45
46
    /**
47
     * Optional. If specified, the user will be asked to create a poll
48
     * and send it to the bot when the button is pressed. Available in private chats only.
49
     *
50
     * @var KeyboardButtonPollType
51
     */
52
    public $requestPoll;
53
54
    /**
55
     * Optional. If specified, the described Web App will be launched when the button is pressed.
56
     * The Web App will be able to send a “web_app_data” service message. Available in private chats only.
57 13
     *
58
     * @var WebAppInfoType|null
59 13
     */
60 13
    public $webApp;
61 13
62 13
    /**
63
     * @throws BadArgumentException
64
     */
65 13
    public static function create(string $text, array $data = null): KeyboardButtonType
66
    {
67
        $instance = new static();
68
        $instance->text = $text;
69
        if ($data) {
70
            $instance->fill($data);
71
        }
72
73
        return $instance;
74
    }
75
}
76