Passed
Push β€” master ( 98ed5e...e88d5b )
by Nikolay
01:11 queued 11s
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
    public const EMOJI_DICE = '🎲';
29
    public const EMOJI_DARTS = '🎯';
30
    public const EMOJI_BASKETBALL = 'πŸ€';
31
    public const EMOJI_FOOTBALL = '⚽';
32
    public const EMOJI_SLOT_MACHINE = '🎰';
33
34
    /**
35
     * Emoji on which the dice throw animation is based.
36
     * Currently, must be one of β€œπŸŽ²β€, β€œπŸŽ―β€, β€œπŸ€β€, β€œβš½β€, or β€œπŸŽ°β€.
37
     * Dice can have values 1-6 for β€œπŸŽ²β€ and β€œπŸŽ―β€, values 1-5 for β€œπŸ€β€ and β€œβš½β€,
38
     * and values 1-64 for β€œπŸŽ°β€. Defaults to β€œπŸŽ²β€.
39
     *
40
     * @var string|null
41
     */
42
    public $emoji;
43
44
    /**
45
     * @param int|string $chatId
46
     *
47
     * @throws BadArgumentException
48
     */
49 1
    public static function create($chatId, array $data = null): SendDiceMethod
50
    {
51 1
        $instance = new static();
52 1
        $instance->chatId = $chatId;
53
54 1
        if ($data) {
55 1
            $instance->fill($data);
56
        }
57
58 1
        return $instance;
59
    }
60
61
    /**
62
     * @param $chatId
63
     *
64
     * @throws BadArgumentException
65
     */
66 1
    public static function createWithDice($chatId, array $data = null): SendDiceMethod
67
    {
68 1
        $instance = static::create($chatId, $data);
69 1
        $instance->emoji = static::EMOJI_DICE;
70
71 1
        return $instance;
72
    }
73
74
    /**
75
     * @param $chatId
76
     *
77
     * @throws BadArgumentException
78
     */
79 1
    public static function createWithDarts($chatId, array $data = null): SendDiceMethod
80
    {
81 1
        $instance = static::create($chatId, $data);
82 1
        $instance->emoji = self::EMOJI_DARTS;
83
84 1
        return $instance;
85
    }
86
87
    /**
88
     * @param $chatId
89
     *
90
     * @throws BadArgumentException
91
     */
92 1
    public static function createWithBasketball($chatId, array $data = null): SendDiceMethod
93
    {
94 1
        $instance = static::create($chatId, $data);
95 1
        $instance->emoji = self::EMOJI_BASKETBALL;
96
97 1
        return $instance;
98
    }
99
100
    /**
101
     * @param $chatId
102
     *
103
     * @throws BadArgumentException
104
     */
105 1
    public static function createWithFootBall($chatId, array $data = null): SendDiceMethod
106
    {
107 1
        $instance = static::create($chatId, $data);
108 1
        $instance->emoji = self::EMOJI_FOOTBALL;
109
110 1
        return $instance;
111
    }
112
113
    /**
114
     * @param $chatId
115
     *
116
     * @throws BadArgumentException
117
     */
118 1
    public static function createWithSlotMachine($chatId, array $data = null): SendDiceMethod
119
    {
120 1
        $instance = static::create($chatId, $data);
121 1
        $instance->emoji = self::EMOJI_SLOT_MACHINE;
122
123 1
        return $instance;
124
    }
125
}
126