Completed
Push — master ( 24b2c2...c2a3d2 )
by Camilo
11s
created

EditMessageMedia::bindToObject()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 2
dl 0
loc 15
ccs 0
cts 9
cp 0
crap 12
rs 9.7666
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\TelegramResponse;
12
use unreal4u\TelegramAPI\Telegram\Types\Custom\ResultBoolean;
13
use unreal4u\TelegramAPI\Telegram\Types\Inline\Keyboard\Markup;
14
use unreal4u\TelegramAPI\Telegram\Types\InputMedia;
15
use unreal4u\TelegramAPI\Telegram\Types\Message;
16
17
/**
18
 * Use this method to edit audio, document, photo, or video messages. If a message is a part of a message album, then it
19
 * can be edited only to a photo or a video. Otherwise, message type can be changed arbitrarily. When inline message is
20
 * edited, new file can't be uploaded. Use previously uploaded file via its file_id or specify a URL. On success, if the
21
 * edited message was sent by the bot, the edited Message is returned, otherwise True is returned.
22
 *
23
 * Objects defined as-is july 2018
24
 *
25
 * @see https://core.telegram.org/bots/api#editmessagemedia
26
 */
27
class EditMessageMedia extends TelegramMethods
28
{
29
    /**
30
     * Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target
31
     * channel (in the format @channelusername)
32
     * @var string
33
     */
34
    public $chat_id = '';
35
36
    /**
37
     * Required if inline_message_id is not specified. Unique identifier of the sent message
38
     * @var int
39
     */
40
    public $message_id = 0;
41
42
    /**
43
     * Required if chat_id and message_id are not specified. Identifier of the inline message
44
     * @var string
45
     */
46
    public $inline_message_id = '';
47
48
    /**
49
     * A JSON-serialized object for a new media content of the message
50
     * @var InputMedia
51
     */
52
    public $media;
53
54
    /**
55
     * Optional. A JSON-serialized object for an inline keyboard.
56
     * @var Markup
57
     */
58
    public $reply_markup;
59
60
    public function getMandatoryFields(): array
61
    {
62
        $returnValue[] = 'media';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$returnValue was never initialized. Although not strictly required by PHP, it is generally a good practice to add $returnValue = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
63
        $this->mandatoryUserOrInlineMessageId($returnValue);
64
        return $returnValue;
65
    }
66
67
    /**
68
     * @param TelegramRawData $data
69
     * @param LoggerInterface $logger
70
     * @return TelegramTypes
71
     * @throws InvalidResultType
72
     */
73
    public static function bindToObject(TelegramResponse $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(sprintf(
83
                    'Result is of type: %s. Expecting one of array or boolean',
84
                    $typeOfResult
85
                ));
86
        }
87
    }
88
}
89