Passed
Push β€” master ( bd5fab...a6cda5 )
by Nikolay
01:17 queued 11s
created

SendDiceMethod::createWithDice()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 6
ccs 0
cts 4
cp 0
rs 10
cc 1
nc 1
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
    public const EMOJI_DICE = '🎲';
29
    public const EMOJI_DARTS = '🎯';
30
31
    /**
32
     * Emoji on which the dice throw animation is based. Currently, must be one of β€œπŸŽ²β€ or β€œπŸŽ―β€. Defauts to β€œπŸŽ²β€.
33
     *
34
     * @var string|null
35
     */
36
    public $emoji;
37
38
    /**
39
     * @param int|string $chatId
40
     *
41
     * @throws BadArgumentException
42
     */
43
    public static function create($chatId, array $data = null): SendDiceMethod
44
    {
45
        $instance = new static();
46
        $instance->chatId = $chatId;
47
48
        if ($data) {
49
            $instance->fill($data);
50
        }
51
52
        return $instance;
53
    }
54
55
    /**
56
     * @param $chatId
57
     *
58
     * @throws BadArgumentException
59
     */
60
    public static function createWithDice($chatId, array $data = null): SendDiceMethod
61
    {
62
        $instance = static::create($chatId, $data);
63
        $instance->emoji = static::EMOJI_DICE;
64
65
        return $instance;
66
    }
67
68
    /**
69
     * @param $chatId
70
     *
71
     * @throws BadArgumentException
72
     */
73
    public static function createWithDarts($chatId, array $data = null): SendDiceMethod
74
    {
75
        $instance = static::create($chatId, $data);
76
        $instance->emoji = self::EMOJI_DARTS;
77
78
        return $instance;
79
    }
80
}
81