Completed
Push — master ( 62cb7b...4b7fdd )
by Nikolay
02:34
created

SendPhotoMethod::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 10
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 3
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TgBotApi\BotApiBase\Method;
6
7
use TgBotApi\BotApiBase\Method\Interfaces\HasParseModeVariableInterface;
8
use TgBotApi\BotApiBase\Method\Traits\CaptionVariablesTrait;
9
use TgBotApi\BotApiBase\Method\Traits\FillFromArrayTrait;
10
use TgBotApi\BotApiBase\Method\Traits\SendToChatVariablesTrait;
11
use TgBotApi\BotApiBase\Type\InputFileType;
12
13
/**
14
 * Class SendPhotoMethod.
15
 *
16
 * @see https://core.telegram.org/bots/api#sendphoto
17
 */
18
class SendPhotoMethod implements HasParseModeVariableInterface
19
{
20
    use FillFromArrayTrait;
21
    use SendToChatVariablesTrait;
22
    use CaptionVariablesTrait;
23
24
    /**
25
     * Photo to send. Pass a file_id as String to send a photo that exists on the Telegram servers (recommended),
26
     * pass an HTTP URL as a String for Telegram to get a photo from the Internet,
27
     * or upload a new photo using multipart/form-data.
28
     *
29
     * @var InputFileType|string
30
     */
31
    public $photo;
32
33
    /**
34
     * @param int|string           $chatId
35
     * @param InputFileType|string $photo
36
     * @param array|null           $data
37
     *
38
     * @throws \TgBotApi\BotApiBase\Exception\BadArgumentException
39
     *
40
     * @return SendPhotoMethod
41
     */
42 2
    public static function create($chatId, $photo, array $data = null): SendPhotoMethod
43
    {
44 2
        $instance = new static();
45 2
        $instance->chatId = $chatId;
46 2
        $instance->photo = $photo;
47 2
        if ($data) {
48 1
            $instance->fill($data);
49
        }
50
51 2
        return $instance;
52
    }
53
}
54