Document::fromArray()   A
last analyzed

Complexity

Conditions 3
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 1
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * This phpFile is auto-generated.
5
 */
6
7
declare(strict_types=1);
8
9
namespace AurimasNiekis\TdLibSchema;
10
11
/**
12
 * Describes a document of any type.
13
 */
14
class Document extends TdObject
15
{
16
    public const TYPE_NAME = 'document';
17
18
    /**
19
     * Original name of the file; as defined by the sender.
20
     *
21
     * @var string
22
     */
23
    protected string $fileName;
24
25
    /**
26
     * MIME type of the file; as defined by the sender.
27
     *
28
     * @var string
29
     */
30
    protected string $mimeType;
31
32
    /**
33
     * Document minithumbnail; may be null.
34
     *
35
     * @var Minithumbnail|null
36
     */
37
    protected ?Minithumbnail $minithumbnail;
38
39
    /**
40
     * Document thumbnail in JPEG or PNG format (PNG will be used only for background patterns); as defined by the sender; may be null.
41
     *
42
     * @var PhotoSize|null
43
     */
44
    protected ?PhotoSize $thumbnail;
45
46
    /**
47
     * File containing the document.
48
     *
49
     * @var File
50
     */
51
    protected File $document;
52
53
    public function __construct(string $fileName, string $mimeType, ?Minithumbnail $minithumbnail, ?PhotoSize $thumbnail, File $document)
54
    {
55
        $this->fileName      = $fileName;
56
        $this->mimeType      = $mimeType;
57
        $this->minithumbnail = $minithumbnail;
58
        $this->thumbnail     = $thumbnail;
59
        $this->document      = $document;
60
    }
61
62
    public static function fromArray(array $array): Document
63
    {
64
        return new static(
65
            $array['file_name'],
66
            $array['mime_type'],
67
            (isset($array['minithumbnail']) ? TdSchemaRegistry::fromArray($array['minithumbnail']) : null),
68
            (isset($array['thumbnail']) ? TdSchemaRegistry::fromArray($array['thumbnail']) : null),
69
            TdSchemaRegistry::fromArray($array['document']),
70
        );
71
    }
72
73
    public function typeSerialize(): array
74
    {
75
        return [
76
            '@type'         => static::TYPE_NAME,
77
            'file_name'     => $this->fileName,
78
            'mime_type'     => $this->mimeType,
79
            'minithumbnail' => (isset($this->minithumbnail) ? $this->minithumbnail : null),
80
            'thumbnail'     => (isset($this->thumbnail) ? $this->thumbnail : null),
81
            'document'      => $this->document->typeSerialize(),
82
        ];
83
    }
84
85
    public function getFileName(): string
86
    {
87
        return $this->fileName;
88
    }
89
90
    public function getMimeType(): string
91
    {
92
        return $this->mimeType;
93
    }
94
95
    public function getMinithumbnail(): ?Minithumbnail
96
    {
97
        return $this->minithumbnail;
98
    }
99
100
    public function getThumbnail(): ?PhotoSize
101
    {
102
        return $this->thumbnail;
103
    }
104
105
    public function getDocument(): File
106
    {
107
        return $this->document;
108
    }
109
}
110