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

InlineKeyboardButton::validate()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
rs 9.2
ccs 8
cts 8
cp 1
cc 4
eloc 7
nc 6
nop 0
crap 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