Completed
Push — master ( 4dcabc...3436f3 )
by Camilo
15s queued 15s
created

EditMessageText   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 36.36%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 5
dl 0
loc 66
ccs 4
cts 11
cp 0.3636
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getMandatoryFields() 0 6 1
A bindToObject() 0 12 3
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\Message;
15
16
/**
17
 * Use this method to edit text messages sent by the bot or via the bot (for inline bots). On success, if edited message
18
 * is sent by the bot, the edited Message is returned, otherwise True is returned
19
 *
20
 * Objects defined as-is july 2016
21
 *
22
 * @see https://core.telegram.org/bots/api#editmessagetext
23
 */
24
class EditMessageText extends TelegramMethods
25
{
26
    /**
27
     * Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target
28
     * channel (in the format @channelusername)
29
     * @var string
30
     */
31
    public $chat_id = '';
32
33
    /**
34
     * Required if inline_message_id is not specified. Unique identifier of the sent message
35
     * @var int
36
     */
37
    public $message_id = 0;
38
39
    /**
40
     * Required if chat_id and message_id are not specified. Identifier of the inline message
41
     * @var string
42
     */
43
    public $inline_message_id = '';
44
45
    /**
46
     * New text of the message
47
     * @var string
48
     */
49
    public $text = '';
50
51
    /**
52
     * Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs
53
     * in your bot's message
54
     * @var string
55
     */
56
    public $parse_mode = '';
57
58
    /**
59
     * Optional. Disables link previews for links in this message
60
     * @var boolean
61
     */
62
    public $disable_web_page_preview = false;
63
64
    /**
65
     * Optional. A JSON-serialized object for an inline keyboard.
66
     * @var Markup
67
     */
68
    public $reply_markup;
69
70 4
    public function getMandatoryFields(): array
71
    {
72 4
        $returnValue[] = 'text';
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...
73 4
        $this->mandatoryUserOrInlineMessageId($returnValue);
74 4
        return $returnValue;
75
    }
76
77
    public static function bindToObject(TelegramResponse $data, LoggerInterface $logger): TelegramTypes
78
    {
79
        $typeOfResult = $data->getTypeOfResult();
80
        switch ($typeOfResult) {
81
            case 'array':
82
                return new Message($data->getResult(), $logger);
83
            case 'boolean':
84
                return new ResultBoolean($data->getResultBoolean(), $logger);
85
            default:
86
                throw new InvalidResultType('Result is of type: %s. Expecting one of array or boolean');
87
        }
88
    }
89
}
90