Passed
Push — master ( c05883...1d5c29 )
by Nikolay
02:30
created

InlineQueryResultDocumentType::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 18
ccs 0
cts 17
cp 0
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 5
crap 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TgBotApi\BotApiBase\Type\InlineQueryResult;
6
7
use TgBotApi\BotApiBase\Method\Interfaces\HasParseModeVariableInterface;
8
use TgBotApi\BotApiBase\Method\Traits\FillFromArrayTrait;
9
use TgBotApi\BotApiBase\Type\InputMessageContent\InputMessageContentType;
10
11
/**
12
 * Class InlineQueryResultDocumentType.
13
 *
14
 * Represents a link to a file. By default, this file will be sent by the user with an optional caption.
15
 * Alternatively, you can use input_message_content to send a message with the specified content instead of the file.
16
 * Currently, only .PDF and .ZIP files can be sent using this method.
17
 *
18
 * @see https://core.telegram.org/bots/api#inlinequeryresultdocument
19
 */
20
class InlineQueryResultDocumentType extends InlineQueryResultType implements HasParseModeVariableInterface
21
{
22
    use FillFromArrayTrait;
23
    const MIME_TYPE_PDF = 'application/pdf';
24
    const MIME_TYPE_ZIP = 'application/zip';
25
26
    /**
27
     * Title for the result;.
28
     *
29
     * @var string
30
     */
31
    public $title;
32
33
    /**
34
     * A valid URL for the file.
35
     *
36
     * @var string
37
     */
38
    public $documentUrl;
39
40
    /**
41
     * Mime type of the content of the file, either “application/pdf” or “application/zip”.
42
     *
43
     * @var string
44
     *
45
     * @see InlineQueryResultDocumentType::MIME_TYPE_PDF, InlineQueryResultDocumentType::MIME_TYPE_ZIP
46
     */
47
    public $mimeType;
48
49
    /**
50
     * Optional. Caption of the document to be sent, 0-1024 characters.
51
     *
52
     * @var string|null
53
     */
54
    public $caption;
55
56
    /**
57
     * Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic,
58
     * fixed-width text or inline URLs in the media caption.
59
     *
60
     * @var string|null
61
     */
62
    public $parseMode;
63
64
    /**
65
     * Optional. Short description of the result.
66
     *
67
     * @var string|null
68
     */
69
    public $description;
70
71
    /**
72
     * Optional. Content of the message to be sent instead of the file.
73
     *
74
     * @var InputMessageContentType|null
75
     */
76
    public $inputMessageContent;
77
78
    /**
79
     * Optional. URL of the thumbnail (jpeg only) for the file.
80
     *
81
     * @var string|null
82
     */
83
    public $thumbUrl;
84
85
    /**
86
     * Optional. Thumbnail width.
87
     *
88
     * @var int|null
89
     */
90
    public $thumbWidth;
91
92
    /**
93
     * Optional. Thumbnail height.
94
     *
95
     * @var int|null
96
     */
97
    public $thumbHeight;
98
99
    /**
100
     * @param string     $id
101
     * @param string     $title
102
     * @param string     $documentUrl
103
     * @param string     $mimeType
104
     * @param array|null $data
105
     *
106
     * @throws \TgBotApi\BotApiBase\Exception\BadArgumentException
107
     *
108
     * @return InlineQueryResultDocumentType
109
     */
110
    public static function create(
111
        string $id,
112
        string $title,
113
        string $documentUrl,
114
        string $mimeType,
115
        array $data = null
116
    ): InlineQueryResultDocumentType {
117
        $instance = new static();
118
        $instance->type = static::TYPE_DOCUMENT;
119
        $instance->id = $id;
120
        $instance->title = $title;
121
        $instance->documentUrl = $documentUrl;
122
        $instance->$mimeType = $mimeType;
123
        if ($data) {
124
            $instance->fill($data);
125
        }
126
127
        return $instance;
128
    }
129
}
130