Passed
Push — master ( f0f514...a1b81d )
by Artem
01:46
created

IPAddress::__get()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 5
rs 10
cc 2
nc 1
nop 1
1
<?php
2
3
// ---------------------------------------------------------------------
4
//
5
//  Copyright (C) 2018-2024 Artem Rodygin
6
//
7
//  You should have received a copy of the MIT License along with
8
//  this file. If not, see <https://opensource.org/licenses/MIT>.
9
//
10
// ---------------------------------------------------------------------
11
12
namespace Linode\Networking;
13
14
use Linode\Entity;
15
16
/**
17
 * An IP address that exists in Linode's system, either IPv4 or IPv6.
18
 *
19
 * @property string         $address     The IP address.
20
 * @property string         $type        The type of address this is.
21
 * @property bool           $public      Whether this is a public or private IP address.
22
 * @property null|string    $rdns        The reverse DNS assigned to this address. For public IPv4 addresses, this will be
23
 *                                       set to a default value provided by Linode if not explicitly set.
24
 * @property string         $region      The Region this IP address resides in.
25
 * @property int            $linode_id   The ID of the Linode this address currently belongs to. For IPv4 addresses, this
26
 *                                       is by default the Linode that this address was assigned to on creation, and these
27
 *                                       addresses my be moved using the /networking/ipv4/assign endpoint. For SLAAC and
28
 *                                       link-local addresses, this value may not be changed.
29
 * @property null|string    $gateway     The default gateway for this address.
30
 * @property string         $subnet_mask The mask that separates host bits from network bits for this address.
31
 * @property int            $prefix      The number of bits set in the subnet mask.
32
 * @property null|NATConfig $vpc_nat_1_1 IPv4 address configured as a 1:1 NAT for this Interface. If no address is
33
 *                                       configured as a 1:1 NAT, `null` is returned.
34
 *                                       **Note:** Only allowed for `vpc` type Interfaces.
35
 */
36
class IPAddress extends Entity
37
{
38
    // Available fields.
39
    public const FIELD_ADDRESS     = 'address';
40
    public const FIELD_TYPE        = 'type';
41
    public const FIELD_PUBLIC      = 'public';
42
    public const FIELD_RDNS        = 'rdns';
43
    public const FIELD_REGION      = 'region';
44
    public const FIELD_LINODE_ID   = 'linode_id';
45
    public const FIELD_GATEWAY     = 'gateway';
46
    public const FIELD_SUBNET_MASK = 'subnet_mask';
47
    public const FIELD_PREFIX      = 'prefix';
48
    public const FIELD_VPC_NAT_1_1 = 'vpc_nat_1_1';
49
50
    // Extra fields for POST/PUT requests.
51
    public const FIELD_IPS = 'ips';
52
53
    // `FIELD_TYPE` values.
54
    public const TYPE_IPV4       = 'ipv4';
55
    public const TYPE_IPV6       = 'ipv6';
56
    public const TYPE_IPV6_POOL  = 'ipv6/pool';
57
    public const TYPE_IPV6_RANGE = 'ipv6/range';
58
59
    /**
60
     * @codeCoverageIgnore This method was autogenerated.
61
     */
62
    public function __get(string $name): mixed
63
    {
64
        return match ($name) {
65
            self::FIELD_VPC_NAT_1_1 => null === $this->data[$name] ? null : new NATConfig($this->client, $this->data[$name]),
66
            default                 => parent::__get($name),
67
        };
68
    }
69
}
70