SetNetworkType::fromArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
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
 * Sets the current network type. Can be called before authorization. Calling this method forces all network connections to reopen, mitigating the delay in switching between different networks, so it should be called whenever the network is changed, even if the network type remains the same. Network type is used to check whether the library can use the network at all and also for collecting detailed network data usage statistics.
13
 */
14
class SetNetworkType extends TdFunction
15
{
16
    public const TYPE_NAME = 'setNetworkType';
17
18
    /**
19
     * The new network type. By default, networkTypeOther.
20
     *
21
     * @var NetworkType
22
     */
23
    protected NetworkType $type;
24
25
    public function __construct(NetworkType $type)
26
    {
27
        $this->type = $type;
28
    }
29
30
    public static function fromArray(array $array): SetNetworkType
31
    {
32
        return new static(
33
            TdSchemaRegistry::fromArray($array['type']),
34
        );
35
    }
36
37
    public function typeSerialize(): array
38
    {
39
        return [
40
            '@type' => static::TYPE_NAME,
41
            'type'  => $this->type->typeSerialize(),
42
        ];
43
    }
44
45
    public function getType(): NetworkType
46
    {
47
        return $this->type;
48
    }
49
}
50