TermsOfService::typeSerialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 7
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 PHPTdGram\Schema;
10
11
/**
12
 * Contains Telegram terms of service.
13
 */
14
class TermsOfService extends TdObject
15
{
16
    public const TYPE_NAME = 'termsOfService';
17
18
    /**
19
     * Text of the terms of service.
20
     */
21
    protected FormattedText $text;
22
23
    /**
24
     * The minimum age of a user to be able to accept the terms; 0 if any.
25
     */
26
    protected int $minUserAge;
27
28
    /**
29
     * True, if a blocking popup with terms of service must be shown to the user.
30
     */
31
    protected bool $showPopup;
32
33
    public function __construct(FormattedText $text, int $minUserAge, bool $showPopup)
34
    {
35
        $this->text       = $text;
36
        $this->minUserAge = $minUserAge;
37
        $this->showPopup  = $showPopup;
38
    }
39
40
    public static function fromArray(array $array): TermsOfService
41
    {
42
        return new static(
43
            TdSchemaRegistry::fromArray($array['text']),
44
            $array['min_user_age'],
45
            $array['show_popup'],
46
        );
47
    }
48
49
    public function typeSerialize(): array
50
    {
51
        return [
52
            '@type'        => static::TYPE_NAME,
53
            'text'         => $this->text->typeSerialize(),
54
            'min_user_age' => $this->minUserAge,
55
            'show_popup'   => $this->showPopup,
56
        ];
57
    }
58
59
    public function getText(): FormattedText
60
    {
61
        return $this->text;
62
    }
63
64
    public function getMinUserAge(): int
65
    {
66
        return $this->minUserAge;
67
    }
68
69
    public function getShowPopup(): bool
70
    {
71
        return $this->showPopup;
72
    }
73
}
74