Completed
Push — master ( 4ede18...f88253 )
by Camilo
06:20
created

StopMessageLiveLocation::bindToObject()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 3
nop 2
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace unreal4u\TelegramAPI\Telegram\Methods;
6
7
use Psr\Log\LoggerInterface;
8
use unreal4u\TelegramAPI\Abstracts\TelegramMethods;
9
use unreal4u\TelegramAPI\Abstracts\TelegramTypes;
10
use unreal4u\TelegramAPI\Exceptions\InvalidResultType;
11
use unreal4u\TelegramAPI\InternalFunctionality\TelegramRawData;
12
use unreal4u\TelegramAPI\Telegram\Types\Custom\ResultBoolean;
13
use unreal4u\TelegramAPI\Telegram\Types\Inline\Keyboard\Markup;
14
use unreal4u\TelegramAPI\Telegram\Types\Message;
15
16
/**
17
 * Use this method to stop updating a live location message sent by the bot or via the bot (for inline bots) before
18
 * live_period expires. On success, if the message was sent by the bot, the sent Message is returned, otherwise True is
19
 * returned
20
 *
21
 * Objects defined as-is october 2017
22
 *
23
 * @see https://core.telegram.org/bots/api#stopmessagelivelocation
24
 */
25
class StopMessageLiveLocation extends TelegramMethods
26
{
27
    /**
28
     * Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target
29
     * channel (in the format @channelusername)
30
     * @var string
31
     */
32
    public $chat_id = '';
33
34
    /**
35
     * Required if inline_message_id is not specified. Unique identifier of the sent message
36
     * @var int
37
     */
38
    public $message_id = 0;
39
40
    /**
41
     * Required if chat_id and message_id are not specified. Identifier of the inline message
42
     * @var string
43
     */
44
    public $inline_message_id = '';
45
46
    /**
47
     * Optional. A JSON-serialized object for an inline keyboard.
48
     * @var Markup
49
     */
50
    public $reply_markup;
51
52
    public function getMandatoryFields(): array
53
    {
54
        $returnValue = [];
55
        return $this->mandatoryUserOrInlineMessageId($returnValue);
56
    }
57
58
    public static function bindToObject(TelegramRawData $data, LoggerInterface $logger): TelegramTypes
59
    {
60
        $typeOfResult = $data->getTypeOfResult();
61
        switch ($typeOfResult) {
62
            case 'array':
63
                return new Message($data->getResult(), $logger);
64
            case 'boolean':
65
                return new ResultBoolean($data->getResultBoolean(), $logger);
66
            default:
67
                throw new InvalidResultType('Result is of type: %s. Expecting one of array or boolean');
68
        }
69
    }
70
}
71