Edit::editInlineMessageText()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 5
dl 0
loc 13
ccs 0
cts 7
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the PhpBotFramework.
5
 *
6
 * PhpBotFramework is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU Lesser General Public License as
8
 * published by the Free Software Foundation, version 3.
9
 *
10
 * PhpBotFramework is distributed in the hope that it will be useful, but
11
 * WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
 * Lesser General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Lesser General Public License
16
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
 */
18
19
namespace PhpBotFramework\Core;
20
21
/**
22
 * \class Edit
23
 * \brief All API Methods that edit a message.
24
 */
25
trait Edit
26
{
27
    abstract protected function execRequest(string $url);
28
29
    /** @internal
30
      * \brief Contains parameters of the next request. */
31
    protected $parameters;
32
33
    /**
34
     * \addtogroup Api Api Methods
35
     * @{
36
     */
37
38
    /**
39
     * \brief Edit text of a message sent by the bot.
40
     * \details Use this method to edit text and game messages sent by the bot. [API reference](https://core.telegram.org/bots/api#editmessagetext)
41
     * @param int $message_id Unique identifier of the sent message.
42
     * @param string $text New text of the message.
43
     * @param string $reply_markup Reply markup of the message will have (will be removed if this is null).
44
     * @param string $parse_mode <i>Optional</i>. Send Markdown or HTML.
45
     * @param bool $disable_web_preview <i>Optional</i>. Disables link previews for links in this message.
46
     * @return Message|false Message edited, false otherwise.
47
     */
48 1 View Code Duplication
    public function editMessageText(int $message_id, string $text, string $reply_markup = null, string $parse_mode = 'HTML', bool $disable_web_preview = true)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
49
    {
50
51 1
        $this->parameters = [
52 1
            'chat_id' => $this->_chat_id,
0 ignored issues
show
Bug introduced by
The property _chat_id does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
53 1
            'message_id' => $message_id,
54 1
            'text' => $text,
55 1
            'reply_markup' => $reply_markup,
56 1
            'parse_mode' => $parse_mode,
57 1
            'disable_web_page_preview' => $disable_web_preview,
58
        ];
59
60 1
        return $this->processRequest('editMessageText', 'Message');
0 ignored issues
show
Bug introduced by
It seems like processRequest() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
61
    }
62
63
    /**
64
     * \brief Edit text of a message sent via the bot.
65
     * \details Use this method to edit text messages sent via the bot (for inline queries). [API reference](https://core.telegram.org/bots/api#editmessagetext)
66
     * @param string $inline_message_id  Identifier of the inline message.
67
     * @param string $text New text of the message.
68
     * @param string $reply_markup Reply markup of the message will have (will be removed if this is null).
69
     * @param string $parse_mode <i>Optional</i>. Send Markdown or HTML.
70
     * @param bool $disable_web_preview <i>Optional</i>. Disables link previews for links in this message.
71
     * @return bool True on success.
72
     */
73
    public function editInlineMessageText(string $inline_message_id, string $text, string $reply_markup = null, string $parse_mode = 'HTML', bool $disable_web_preview = false) : bool
74
    {
75
76
        $parameters = [
77
            'inline_message_id' => $inline_message_id,
78
            'text' => $text,
79
            'reply_markup' => $reply_markup,
80
            'parse_mode' => $parse_mode,
81
            'disable_web_page_preview' => $disable_web_preview,
82
        ];
83
84
        return $this->execRequest('editMessageText?' . http_build_query($parameters));
85
    }
86
87
    /**
88
     * \brief Edit only the inline keyboard of a message.
89
     * \details[API reference](https://core.telegram.org/bots/api#editmessagereplymarkup)
90
     * @param int $message_id Identifier of the message to edit
91
     * @param string $inline_keyboard Inlike keyboard array. [API reference](https://core.telegram.org/bots/api#inlinekeyboardmarkup)
92
     * @return Message|false Message edited, false otherwise.
93
     */
94
    public function editMessageReplyMarkup(int $message_id, string $inline_keyboard)
95
    {
96
97
        $this->parameters = [
98
            'chat_id' => $this->_chat_id,
99
            'message_id' => $message_id,
100
            'reply_markup' => $inline_keyboard,
101
        ];
102
103
        return $this->processRequest('editMessageReplyMarkup', 'Message');
0 ignored issues
show
Bug introduced by
It seems like processRequest() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
104
    }
105
106
    /** @} */
107
}
108