Passed
Pull Request — master (#62)
by
unknown
11:14
created

MenuButtonType::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 5
c 1
b 0
f 1
dl 0
loc 9
rs 10
cc 2
nc 2
nop 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
10
/**
11
 * Class MenuButtonType.
12
 *
13
 * @see https://core.telegram.org/bots/api#menubutton
14
 */
15
class MenuButtonType
16
{
17
    use FillFromArrayTrait;
18
19
    public const TYPE_COMMANDS = 'commands';
20
    public const TYPE_WEB_APP = 'web_app';
21
    public const TYPE_DEFAULT = 'default';
22
23
    /**
24
     * Type of the button must be one of the list: commands, web_app, default
25
     *
26
     * @var string
27
     */
28
    public $type;
29
30
    /**
31
     * Text on the button. Required for type 'web_app'
32
     *
33
     * @var string|null
34
     */
35
    public $text;
36
37
    /**
38
     * Description of the Web App that will be launched when the user presses the button. Required for type 'web_app'
39
     *
40
     * @var WebAppInfoType|null
41
     */
42
    public $webApp;
43
44
    /**
45
     * @param string     $type
46
     * @param array|null $data
47
     *
48
     * @throws BadArgumentException
49
     *
50
     * @return MenuButtonType
51
     */
52
    public static function create(string $type, array $data = null): MenuButtonType
53
    {
54
        $instance = new static();
55
        $instance->type = $type;
56
        if ($data) {
57
            $instance->fill($data);
58
        }
59
60
        return $instance;
61
    }
62
}
63