PageBlockEmbeddedPost::getUrl()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
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
 * An embedded post.
13
 */
14
class PageBlockEmbeddedPost extends PageBlock
15
{
16
    public const TYPE_NAME = 'pageBlockEmbeddedPost';
17
18
    /**
19
     * Web page URL.
20
     *
21
     * @var string
22
     */
23
    protected string $url;
24
25
    /**
26
     * Post author.
27
     *
28
     * @var string
29
     */
30
    protected string $author;
31
32
    /**
33
     * Post author photo; may be null.
34
     *
35
     * @var Photo|null
36
     */
37
    protected ?Photo $authorPhoto;
38
39
    /**
40
     * Point in time (Unix timestamp) when the post was created; 0 if unknown.
41
     *
42
     * @var int
43
     */
44
    protected int $date;
45
46
    /**
47
     * Post content.
48
     *
49
     * @var PageBlock[]
50
     */
51
    protected array $pageBlocks;
52
53
    /**
54
     * Post caption.
55
     *
56
     * @var PageBlockCaption
57
     */
58
    protected PageBlockCaption $caption;
59
60
    public function __construct(string $url, string $author, ?Photo $authorPhoto, int $date, array $pageBlocks, PageBlockCaption $caption)
61
    {
62
        parent::__construct();
63
64
        $this->url         = $url;
65
        $this->author      = $author;
66
        $this->authorPhoto = $authorPhoto;
67
        $this->date        = $date;
68
        $this->pageBlocks  = $pageBlocks;
69
        $this->caption     = $caption;
70
    }
71
72
    public static function fromArray(array $array): PageBlockEmbeddedPost
73
    {
74
        return new static(
75
            $array['url'],
76
            $array['author'],
77
            (isset($array['author_photo']) ? TdSchemaRegistry::fromArray($array['author_photo']) : null),
78
            $array['date'],
79
            array_map(fn ($x) => TdSchemaRegistry::fromArray($x), $array['pageBlocks']),
80
            TdSchemaRegistry::fromArray($array['caption']),
81
        );
82
    }
83
84
    public function typeSerialize(): array
85
    {
86
        return [
87
            '@type'           => static::TYPE_NAME,
88
            'url'             => $this->url,
89
            'author'          => $this->author,
90
            'author_photo'    => (isset($this->authorPhoto) ? $this->authorPhoto : null),
91
            'date'            => $this->date,
92
            array_map(fn ($x) => $x->typeSerialize(), $this->pageBlocks),
93
            'caption'         => $this->caption->typeSerialize(),
94
        ];
95
    }
96
97
    public function getUrl(): string
98
    {
99
        return $this->url;
100
    }
101
102
    public function getAuthor(): string
103
    {
104
        return $this->author;
105
    }
106
107
    public function getAuthorPhoto(): ?Photo
108
    {
109
        return $this->authorPhoto;
110
    }
111
112
    public function getDate(): int
113
    {
114
        return $this->date;
115
    }
116
117
    public function getPageBlocks(): array
118
    {
119
        return $this->pageBlocks;
120
    }
121
122
    public function getCaption(): PageBlockCaption
123
    {
124
        return $this->caption;
125
    }
126
}
127