Invoice::fromArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 1
dl 0
loc 13
rs 9.9
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
 * Product invoice.
13
 */
14
class Invoice extends TdObject
15
{
16
    public const TYPE_NAME = 'invoice';
17
18
    /**
19
     * ISO 4217 currency code.
20
     *
21
     * @var string
22
     */
23
    protected string $currency;
24
25
    /**
26
     * A list of objects used to calculate the total price of the product.
27
     *
28
     * @var LabeledPricePart[]
29
     */
30
    protected array $priceParts;
31
32
    /**
33
     * True, if the payment is a test payment.
34
     *
35
     * @var bool
36
     */
37
    protected bool $isTest;
38
39
    /**
40
     * True, if the user's name is needed for payment.
41
     *
42
     * @var bool
43
     */
44
    protected bool $needName;
45
46
    /**
47
     * True, if the user's phone number is needed for payment.
48
     *
49
     * @var bool
50
     */
51
    protected bool $needPhoneNumber;
52
53
    /**
54
     * True, if the user's email address is needed for payment.
55
     *
56
     * @var bool
57
     */
58
    protected bool $needEmailAddress;
59
60
    /**
61
     * True, if the user's shipping address is needed for payment.
62
     *
63
     * @var bool
64
     */
65
    protected bool $needShippingAddress;
66
67
    /**
68
     * True, if the user's phone number will be sent to the provider.
69
     *
70
     * @var bool
71
     */
72
    protected bool $sendPhoneNumberToProvider;
73
74
    /**
75
     * True, if the user's email address will be sent to the provider.
76
     *
77
     * @var bool
78
     */
79
    protected bool $sendEmailAddressToProvider;
80
81
    /**
82
     * True, if the total price depends on the shipping method.
83
     *
84
     * @var bool
85
     */
86
    protected bool $isFlexible;
87
88
    public function __construct(
89
        string $currency,
90
        array $priceParts,
91
        bool $isTest,
92
        bool $needName,
93
        bool $needPhoneNumber,
94
        bool $needEmailAddress,
95
        bool $needShippingAddress,
96
        bool $sendPhoneNumberToProvider,
97
        bool $sendEmailAddressToProvider,
98
        bool $isFlexible
99
    ) {
100
        $this->currency                   = $currency;
101
        $this->priceParts                 = $priceParts;
102
        $this->isTest                     = $isTest;
103
        $this->needName                   = $needName;
104
        $this->needPhoneNumber            = $needPhoneNumber;
105
        $this->needEmailAddress           = $needEmailAddress;
106
        $this->needShippingAddress        = $needShippingAddress;
107
        $this->sendPhoneNumberToProvider  = $sendPhoneNumberToProvider;
108
        $this->sendEmailAddressToProvider = $sendEmailAddressToProvider;
109
        $this->isFlexible                 = $isFlexible;
110
    }
111
112
    public static function fromArray(array $array): Invoice
113
    {
114
        return new static(
115
            $array['currency'],
116
            array_map(fn ($x) => TdSchemaRegistry::fromArray($x), $array['priceParts']),
117
            $array['is_test'],
118
            $array['need_name'],
119
            $array['need_phone_number'],
120
            $array['need_email_address'],
121
            $array['need_shipping_address'],
122
            $array['send_phone_number_to_provider'],
123
            $array['send_email_address_to_provider'],
124
            $array['is_flexible'],
125
        );
126
    }
127
128
    public function typeSerialize(): array
129
    {
130
        return [
131
            '@type'                          => static::TYPE_NAME,
132
            'currency'                       => $this->currency,
133
            array_map(fn ($x)                => $x->typeSerialize(), $this->priceParts),
134
            'is_test'                        => $this->isTest,
135
            'need_name'                      => $this->needName,
136
            'need_phone_number'              => $this->needPhoneNumber,
137
            'need_email_address'             => $this->needEmailAddress,
138
            'need_shipping_address'          => $this->needShippingAddress,
139
            'send_phone_number_to_provider'  => $this->sendPhoneNumberToProvider,
140
            'send_email_address_to_provider' => $this->sendEmailAddressToProvider,
141
            'is_flexible'                    => $this->isFlexible,
142
        ];
143
    }
144
145
    public function getCurrency(): string
146
    {
147
        return $this->currency;
148
    }
149
150
    public function getPriceParts(): array
151
    {
152
        return $this->priceParts;
153
    }
154
155
    public function getIsTest(): bool
156
    {
157
        return $this->isTest;
158
    }
159
160
    public function getNeedName(): bool
161
    {
162
        return $this->needName;
163
    }
164
165
    public function getNeedPhoneNumber(): bool
166
    {
167
        return $this->needPhoneNumber;
168
    }
169
170
    public function getNeedEmailAddress(): bool
171
    {
172
        return $this->needEmailAddress;
173
    }
174
175
    public function getNeedShippingAddress(): bool
176
    {
177
        return $this->needShippingAddress;
178
    }
179
180
    public function getSendPhoneNumberToProvider(): bool
181
    {
182
        return $this->sendPhoneNumberToProvider;
183
    }
184
185
    public function getSendEmailAddressToProvider(): bool
186
    {
187
        return $this->sendEmailAddressToProvider;
188
    }
189
190
    public function getIsFlexible(): bool
191
    {
192
        return $this->isFlexible;
193
    }
194
}
195