Completed
Push — master ( 2171d1...d76c2c )
by Nikolay
06:00
created

ForwardMessageMethod::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 12
c 0
b 0
f 0
ccs 8
cts 8
cp 1
rs 10
cc 2
nc 2
nop 4
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TgBotApi\BotApiBase\Method;
6
7
use TgBotApi\BotApiBase\Exception\BadArgumentException;
8
use TgBotApi\BotApiBase\Method\Interfaces\ForwardMethodAliasInterface;
9
use TgBotApi\BotApiBase\Method\Interfaces\SendMethodAliasInterface;
10
use TgBotApi\BotApiBase\Method\Traits\ChatIdVariableTrait;
11
use TgBotApi\BotApiBase\Method\Traits\FillFromArrayTrait;
12
13
/**
14
 * Class ForwardMessageMethod.
15
 *
16
 * @see https://core.telegram.org/bots/api#forwardmessage
17
 */
18
class ForwardMessageMethod implements SendMethodAliasInterface, ForwardMethodAliasInterface
19
{
20
    use FillFromArrayTrait;
21
    use ChatIdVariableTrait;
22
    /**
23
     * Unique identifier for the chat where the original message was sent
24
     * (or channel username in the format @channelusername).
25
     *
26
     * @var int|string
27
     */
28
    public $fromChatId;
29
30
    /**
31
     * Optional. Sends the message silently. Users will receive a notification with no sound.
32
     *
33
     * @var bool|null
34
     */
35
    public $disableNotification;
36
37
    /**
38
     * Message identifier in the chat specified in from_chat_id.
39
     *
40
     * @var int
41
     */
42
    public $messageId;
43
44
    /**
45
     * @param int|string $chatId
46
     * @param int|string $fromChatId
47
     * @param int        $messageId
48
     * @param array|null $data
49
     *
50
     * @throws BadArgumentException
51
     *
52
     * @return ForwardMessageMethod
53
     */
54 6
    public static function create($chatId, $fromChatId, int $messageId, array $data = null): self
55
    {
56 6
        $instance = new static();
57 6
        $instance->chatId = $chatId;
58 6
        $instance->fromChatId = $fromChatId;
59 6
        $instance->messageId = $messageId;
60
61 6
        if ($data) {
62 3
            $instance->fill($data);
63
        }
64
65 6
        return $instance;
66
    }
67
}
68