AddContact::fromArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
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
 * Adds a user to the contact list or edits an existing contact by their user identifier.
13
 */
14
class AddContact extends TdFunction
15
{
16
    public const TYPE_NAME = 'addContact';
17
18
    /**
19
     * The contact to add or edit; phone number can be empty and needs to be specified only if known, vCard is ignored.
20
     *
21
     * @var Contact
22
     */
23
    protected Contact $contact;
24
25
    /**
26
     * True, if the new contact needs to be allowed to see current user's phone number. A corresponding rule to userPrivacySettingShowPhoneNumber will be added if needed. Use the field UserFullInfo.need_phone_number_privacy_exception to check whether the current user needs to be asked to share their phone number.
27
     *
28
     * @var bool
29
     */
30
    protected bool $sharePhoneNumber;
31
32
    public function __construct(Contact $contact, bool $sharePhoneNumber)
33
    {
34
        $this->contact          = $contact;
35
        $this->sharePhoneNumber = $sharePhoneNumber;
36
    }
37
38
    public static function fromArray(array $array): AddContact
39
    {
40
        return new static(
41
            TdSchemaRegistry::fromArray($array['contact']),
42
            $array['share_phone_number'],
43
        );
44
    }
45
46
    public function typeSerialize(): array
47
    {
48
        return [
49
            '@type'              => static::TYPE_NAME,
50
            'contact'            => $this->contact->typeSerialize(),
51
            'share_phone_number' => $this->sharePhoneNumber,
52
        ];
53
    }
54
55
    public function getContact(): Contact
56
    {
57
        return $this->contact;
58
    }
59
60
    public function getSharePhoneNumber(): bool
61
    {
62
        return $this->sharePhoneNumber;
63
    }
64
}
65