User::fromArray()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 19
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 17
nc 1
nop 1
dl 0
loc 19
rs 9.7
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 PHPTdGram\Schema;
10
11
/**
12
 * Represents a user.
13
 */
14
class User extends TdObject
15
{
16
    public const TYPE_NAME = 'user';
17
18
    /**
19
     * User identifier.
20
     */
21
    protected int $id;
22
23
    /**
24
     * First name of the user.
25
     */
26
    protected string $firstName;
27
28
    /**
29
     * Last name of the user.
30
     */
31
    protected string $lastName;
32
33
    /**
34
     * Username of the user.
35
     */
36
    protected string $username;
37
38
    /**
39
     * Phone number of the user.
40
     */
41
    protected string $phoneNumber;
42
43
    /**
44
     * Current online status of the user.
45
     */
46
    protected UserStatus $status;
47
48
    /**
49
     * Profile photo of the user; may be null.
50
     */
51
    protected ?ProfilePhoto $profilePhoto;
52
53
    /**
54
     * The user is a contact of the current user.
55
     */
56
    protected bool $isContact;
57
58
    /**
59
     * The user is a contact of the current user and the current user is a contact of the user.
60
     */
61
    protected bool $isMutualContact;
62
63
    /**
64
     * True, if the user is verified.
65
     */
66
    protected bool $isVerified;
67
68
    /**
69
     * True, if the user is Telegram support account.
70
     */
71
    protected bool $isSupport;
72
73
    /**
74
     * If non-empty, it contains a human-readable description of the reason why access to this user must be restricted.
75
     */
76
    protected string $restrictionReason;
77
78
    /**
79
     * True, if many users reported this user as a scam.
80
     */
81
    protected bool $isScam;
82
83
    /**
84
     * If false, the user is inaccessible, and the only information known about the user is inside this class. It can't be passed to any method except GetUser.
85
     */
86
    protected bool $haveAccess;
87
88
    /**
89
     * Type of the user.
90
     */
91
    protected UserType $type;
92
93
    /**
94
     * IETF language tag of the user's language; only available to bots.
95
     */
96
    protected string $languageCode;
97
98
    public function __construct(
99
        int $id,
100
        string $firstName,
101
        string $lastName,
102
        string $username,
103
        string $phoneNumber,
104
        UserStatus $status,
105
        ?ProfilePhoto $profilePhoto,
106
        bool $isContact,
107
        bool $isMutualContact,
108
        bool $isVerified,
109
        bool $isSupport,
110
        string $restrictionReason,
111
        bool $isScam,
112
        bool $haveAccess,
113
        UserType $type,
114
        string $languageCode
115
    ) {
116
        $this->id                = $id;
117
        $this->firstName         = $firstName;
118
        $this->lastName          = $lastName;
119
        $this->username          = $username;
120
        $this->phoneNumber       = $phoneNumber;
121
        $this->status            = $status;
122
        $this->profilePhoto      = $profilePhoto;
123
        $this->isContact         = $isContact;
124
        $this->isMutualContact   = $isMutualContact;
125
        $this->isVerified        = $isVerified;
126
        $this->isSupport         = $isSupport;
127
        $this->restrictionReason = $restrictionReason;
128
        $this->isScam            = $isScam;
129
        $this->haveAccess        = $haveAccess;
130
        $this->type              = $type;
131
        $this->languageCode      = $languageCode;
132
    }
133
134
    public static function fromArray(array $array): User
135
    {
136
        return new static(
137
            $array['id'],
138
            $array['first_name'],
139
            $array['last_name'],
140
            $array['username'],
141
            $array['phone_number'],
142
            TdSchemaRegistry::fromArray($array['status']),
143
            (isset($array['profile_photo']) ? TdSchemaRegistry::fromArray($array['profile_photo']) : null),
144
            $array['is_contact'],
145
            $array['is_mutual_contact'],
146
            $array['is_verified'],
147
            $array['is_support'],
148
            $array['restriction_reason'],
149
            $array['is_scam'],
150
            $array['have_access'],
151
            TdSchemaRegistry::fromArray($array['type']),
152
            $array['language_code'],
153
        );
154
    }
155
156
    public function typeSerialize(): array
157
    {
158
        return [
159
            '@type'              => static::TYPE_NAME,
160
            'id'                 => $this->id,
161
            'first_name'         => $this->firstName,
162
            'last_name'          => $this->lastName,
163
            'username'           => $this->username,
164
            'phone_number'       => $this->phoneNumber,
165
            'status'             => $this->status->typeSerialize(),
166
            'profile_photo'      => (isset($this->profilePhoto) ? $this->profilePhoto : null),
167
            'is_contact'         => $this->isContact,
168
            'is_mutual_contact'  => $this->isMutualContact,
169
            'is_verified'        => $this->isVerified,
170
            'is_support'         => $this->isSupport,
171
            'restriction_reason' => $this->restrictionReason,
172
            'is_scam'            => $this->isScam,
173
            'have_access'        => $this->haveAccess,
174
            'type'               => $this->type->typeSerialize(),
175
            'language_code'      => $this->languageCode,
176
        ];
177
    }
178
179
    public function getId(): int
180
    {
181
        return $this->id;
182
    }
183
184
    public function getFirstName(): string
185
    {
186
        return $this->firstName;
187
    }
188
189
    public function getLastName(): string
190
    {
191
        return $this->lastName;
192
    }
193
194
    public function getUsername(): string
195
    {
196
        return $this->username;
197
    }
198
199
    public function getPhoneNumber(): string
200
    {
201
        return $this->phoneNumber;
202
    }
203
204
    public function getStatus(): UserStatus
205
    {
206
        return $this->status;
207
    }
208
209
    public function getProfilePhoto(): ?ProfilePhoto
210
    {
211
        return $this->profilePhoto;
212
    }
213
214
    public function getIsContact(): bool
215
    {
216
        return $this->isContact;
217
    }
218
219
    public function getIsMutualContact(): bool
220
    {
221
        return $this->isMutualContact;
222
    }
223
224
    public function getIsVerified(): bool
225
    {
226
        return $this->isVerified;
227
    }
228
229
    public function getIsSupport(): bool
230
    {
231
        return $this->isSupport;
232
    }
233
234
    public function getRestrictionReason(): string
235
    {
236
        return $this->restrictionReason;
237
    }
238
239
    public function getIsScam(): bool
240
    {
241
        return $this->isScam;
242
    }
243
244
    public function getHaveAccess(): bool
245
    {
246
        return $this->haveAccess;
247
    }
248
249
    public function getType(): UserType
250
    {
251
        return $this->type;
252
    }
253
254
    public function getLanguageCode(): string
255
    {
256
        return $this->languageCode;
257
    }
258
}
259