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

EditMessageLiveLocation::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 edit live location messages sent by the bot or via the bot (for inline bots). A location can be
18
 * edited until its live_period expires or editing is explicitly disabled by a call to stopMessageLiveLocation. On
19
 * success, if the edited message was sent by the bot, the edited Message is returned, otherwise True is returned
20
 *
21
 * Objects defined as-is october 2017
22
 *
23
 * @see https://core.telegram.org/bots/api#editmessagelivelocation
24
 */
25
class EditMessageLiveLocation 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
     * Latitude of new location
48
     * @var float
49
     */
50
    public $latitude = 0.0;
51
52
    /**
53
     * Longitude of new location
54
     * @var float
55
     */
56
    public $longitude = 0.0;
57
58
    /**
59
     * Optional. A JSON-serialized object for an inline keyboard.
60
     * @var Markup
61
     */
62
    public $reply_markup;
63
64
    public function getMandatoryFields(): array
65
    {
66
        $returnValue = [
67
            'longitude',
68
            'latitude',
69
        ];
70
        return $this->mandatoryUserOrInlineMessageId($returnValue);
71
    }
72
73
    public static function bindToObject(TelegramRawData $data, LoggerInterface $logger): TelegramTypes
74
    {
75
        $typeOfResult = $data->getTypeOfResult();
76
        switch ($typeOfResult) {
77
            case 'array':
78
                return new Message($data->getResult(), $logger);
79
            case 'boolean':
80
                return new ResultBoolean($data->getResultBoolean(), $logger);
81
            default:
82
                throw new InvalidResultType('Result is of type: %s. Expecting one of array or boolean');
83
        }
84
    }
85
}
86