Completed
Pull Request — master (#28)
by Nikolay
11:57
created

AddStickerToSetMethod::createBase()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 7
c 0
b 0
f 0
dl 0
loc 15
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\Method\Interfaces\AddMethodAliasInterface;
8
use TgBotApi\BotApiBase\Method\Traits\EmojisVariableTrait;
9
use TgBotApi\BotApiBase\Method\Traits\FillFromArrayTrait;
10
use TgBotApi\BotApiBase\Type\InputFileType;
11
use TgBotApi\BotApiBase\Type\MaskPositionType;
12
13
/**
14
 * Class AddStickerToSetMethod.
15
 *
16
 * @see https://core.telegram.org/bots/api#addstickertoset
17
 */
18
class AddStickerToSetMethod implements AddMethodAliasInterface
19
{
20
    use FillFromArrayTrait;
21
    use EmojisVariableTrait;
22
23
    /**
24
     * User identifier of sticker set owner.
25
     *
26
     * @var int
27
     */
28
    public $userId;
29
30
    /**
31
     * Sticker set name.
32
     *
33
     * @var string
34
     */
35
    public $name;
36
37
    /**
38
     * Optional. Png image with the sticker, must be up to 512 kilobytes in size,
39
     * dimensions must not exceed 512px, and either width or height must be exactly 512px.
40
     * Pass a file_id as a String to send a file that already exists on the Telegram servers,
41
     * pass an HTTP URL as a String for Telegram to get a file from the Internet,
42
     * or upload a new one using multipart/form-data.
43
     *
44
     * @var InputFileType|string|null
45
     */
46
    public $pngSticker;
47
48
    /**
49
     * Optional. TGS animation with the sticker, uploaded using multipart/form-data.
50
     * See https://core.telegram.org/animated_stickers#technical-requirements for technical requirements.
51
     *
52
     * @var InputFileType|null
53
     */
54
    public $tgsSticker;
55
56
    /**
57
     * Optional. A JSON-serialized object for position where the mask should be placed on faces.
58
     *
59
     * @var MaskPositionType|null
60
     */
61
    public $maskPosition;
62
63
    /**
64
     * @param InputFileType|string $pngSticker
65
     *
66
     * @throws \TgBotApi\BotApiBase\Exception\BadArgumentException
67
     *
68
     * @deprecated
69
     * @see AddStickerToSetMethod::createStatic()
70
     */
71 3
    public static function create(
72
        int $userId,
73
        string $name,
74
        $pngSticker,
75
        string $emojis,
76
        array $data = null
77
    ): AddStickerToSetMethod {
78 3
        return static::createStatic($userId, $name, $pngSticker, $emojis, $data);
79
    }
80
81
    /**
82
     * @param InputFileType|string $pngSticker
83
     *
84
     * @throws \TgBotApi\BotApiBase\Exception\BadArgumentException
85
     */
86 3
    public static function createStatic(
87
        int $userId,
88
        string $name,
89
        $pngSticker,
90
        string $emojis,
91
        array $data = null
92
    ): AddStickerToSetMethod {
93 3
        $instance = static::createBase($userId, $name, $emojis, $data);
94 3
        $instance->pngSticker = $pngSticker;
95
96 3
        return $instance;
97
    }
98
99
    /**
100
     * @throws \TgBotApi\BotApiBase\Exception\BadArgumentException
101
     */
102 3
    public static function createAnimated(
103
        int $userId,
104
        string $name,
105
        InputFileType $tgsSticker,
106
        string $emojis,
107
        array $data = null
108
    ): AddStickerToSetMethod {
109 3
        $instance = static::createBase($userId, $name, $emojis, $data);
110 3
        $instance->tgsSticker = $tgsSticker;
111
112 3
        return $instance;
113
    }
114
115
    /**
116
     * @throws \TgBotApi\BotApiBase\Exception\BadArgumentException
117
     */
118 6
    private static function createBase(
119
        int $userId,
120
        string $name,
121
        string $emojis,
122
        array $data = null
123
    ): AddStickerToSetMethod {
124 6
        $instance = new static();
125 6
        $instance->userId = $userId;
126 6
        $instance->name = $name;
127 6
        $instance->emojis = $emojis;
128 6
        if ($data) {
129 6
            $instance->fill($data);
130
        }
131
132 6
        return $instance;
133
    }
134
}
135