Passed
Pull Request — master (#28)
by Nikolay
03:06
created

SendDiceMethod::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 5
c 1
b 0
f 1
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 10
cc 2
nc 2
nop 2
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\SendMethodAliasInterface;
9
use TgBotApi\BotApiBase\Method\Traits\FillFromArrayTrait;
10
use TgBotApi\BotApiBase\Method\Traits\SendToChatVariablesTrait;
11
12
/**
13
 * Class SendDiceMethod.
14
 *
15
 * Use this method to send a dice, which will have a random value from 1 to 6.
16
 * On success, the sent Message is returned.
17
 * (Yes, we're aware of the “proper” singular of die.
18
 * But it's awkward, and we decided to help it change.
19
 * One dice at a time!)
20
 *
21
 * @see https://core.telegram.org/bots/api#senddice
22
 */
23
class SendDiceMethod implements SendMethodAliasInterface
24
{
25
    use SendToChatVariablesTrait;
26
    use FillFromArrayTrait;
27
28
    /**
29
     * @param int|string $chatId
30
     *
31
     * @throws BadArgumentException
32
     */
33 1
    public static function create($chatId, array $data = null): SendDiceMethod
34
    {
35 1
        $instance = new static();
36 1
        $instance->chatId = $chatId;
37
38 1
        if ($data) {
39 1
            $instance->fill($data);
40
        }
41
42 1
        return $instance;
43
    }
44
}
45