Completed
Pull Request — develop (#291)
by Armando
03:51
created

InlineKeyboardButton   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 6
Bugs 2 Features 1
Metric Value
wmc 4
c 6
b 2
f 1
lcom 0
cbo 2
dl 0
loc 18
rs 10
ccs 8
cts 8
cp 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 12 4
1
<?php
2
/**
3
 * This file is part of the TelegramBot package.
4
 *
5
 * (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Longman\TelegramBot\Entities;
12
13
use Longman\TelegramBot\Exception\TelegramException;
14
15
/**
16
 * Class InlineKeyboardButton
17
 *
18
 * @link https://core.telegram.org/bots/api#inlinekeyboardbutton
19
 *
20
 * @method string getText()              Label text on the button
21
 * @method string getUrl()               Optional. HTTP url to be opened when button is pressed
22
 * @method string getCallbackData()      Optional. Data to be sent in a callback query to the bot when button is pressed, 1-64 bytes
23
 * @method string getSwitchInlineQuery() Optional. If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bot's username and the specified inline query in the input field. Can be empty, in which case just the bot’s username will be inserted.
24
 */
25
class InlineKeyboardButton extends Entity
26
{
27
    /**
28
     * {@inheritdoc}
29
     */
30 4
    protected function validate()
31
    {
32 4
        $num_params = 0;
33 4
        foreach (['url', 'callback_data', 'switch_inline_query'] as $param) {
34 4
            if (!empty($this->getProperty($param))) {
35 4
                $num_params++;
36
            }
37
        }
38 4
        if ($num_params !== 1) {
39 3
            throw new TelegramException('You must use only one of these fields: url, callback_data, switch_inline_query!');
40
        }
41 1
    }
42
}
43