Type   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 142
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 46
dl 0
loc 142
ccs 30
cts 30
cp 1
rs 10
c 1
b 0
f 0
wmc 16

1 Method

Rating   Name   Duplication   Size   Complexity  
C getName() 0 33 16
1
<?php
2
3
namespace IPLib\Range;
4
5
/**
6
 * Types of IP address classes.
7
 */
8
class Type
9
{
10
    /**
11
     * Unspecified/unknown address.
12
     *
13
     * @var int
14
     */
15
    const T_UNSPECIFIED = 1;
16
17
    /**
18
     * Reserved/internal use only.
19
     *
20
     * @var int
21
     */
22
    const T_RESERVED = 2;
23
24
    /**
25
     * Refer to source hosts on "this" network.
26
     *
27
     * @var int
28
     */
29
    const T_THISNETWORK = 3;
30
31
    /**
32
     * Internet host loopback address.
33
     *
34
     * @var int
35
     */
36
    const T_LOOPBACK = 4;
37
38
    /**
39
     * Relay anycast address.
40
     *
41
     * @var int
42
     */
43
    const T_ANYCASTRELAY = 5;
44
45
    /**
46
     * "Limited broadcast" destination address.
47
     *
48
     * @var int
49
     */
50
    const T_LIMITEDBROADCAST = 6;
51
52
    /**
53
     * Multicast address assignments - Indentify a group of interfaces.
54
     *
55
     * @var int
56
     */
57
    const T_MULTICAST = 7;
58
59
    /**
60
     * "Link local" address, allocated for communication between hosts on a single link.
61
     *
62
     * @var int
63
     */
64
    const T_LINKLOCAL = 8;
65
66
    /**
67
     * Link local unicast / Linked-scoped unicast.
68
     *
69
     * @var int
70
     */
71
    const T_LINKLOCAL_UNICAST = 9;
72
73
    /**
74
     * Discard-Only address.
75
     *
76
     * @var int
77
     */
78
    const T_DISCARDONLY = 10;
79
80
    /**
81
     * Discard address.
82
     *
83
     * @var int
84
     */
85
    const T_DISCARD = 11;
86
87
    /**
88
     * For use in private networks.
89
     *
90
     * @var int
91
     */
92
    const T_PRIVATENETWORK = 12;
93
94
    /**
95
     * Public address.
96
     *
97
     * @var int
98
     */
99
    const T_PUBLIC = 13;
100
101
    /**
102
     * Carrier-grade NAT address.
103
     *
104
     * @var int
105
     *
106
     * @since 1.10.0
107
     */
108
    const T_CGNAT = 14;
109
110
    /**
111
     * Get the name of a type.
112
     *
113
     * @param int $type
114
     *
115
     * @return string
116
     */
117 463
    public static function getName($type)
118
    {
119
        switch ($type) {
120 463
            case static::T_UNSPECIFIED:
121 9
                return 'Unspecified/unknown address';
122 454
            case static::T_RESERVED:
123 149
                 return 'Reserved/internal use only';
124 305
            case static::T_THISNETWORK:
125 3
                 return 'Refer to source hosts on "this" network';
126 302
            case static::T_LOOPBACK:
127 14
                 return 'Internet host loopback address';
128 288
            case static::T_ANYCASTRELAY:
129 7
                 return 'Relay anycast address';
130 281
            case static::T_LIMITEDBROADCAST:
131 7
                 return '"Limited broadcast" destination address';
132 274
            case static::T_MULTICAST:
133 166
                 return 'Multicast address assignments - Indentify a group of interfaces';
134 108
            case static::T_LINKLOCAL:
135 7
                 return '"Link local" address, allocated for communication between hosts on a single link';
136 101
            case static::T_LINKLOCAL_UNICAST:
137 4
                return 'Link local unicast / Linked-scoped unicast';
138 97
            case static::T_DISCARDONLY:
139 6
                 return 'Discard only';
140 91
            case static::T_DISCARD:
141 6
                 return 'Discard';
142 85
            case static::T_PRIVATENETWORK:
143 42
                 return 'For use in private networks';
144 43
            case static::T_PUBLIC:
145 12
                 return 'Public address';
146 31
            case static::T_CGNAT:
147 4
                return 'Carrier-grade NAT';
148
            default:
149 27
                return $type === null ? 'Unknown type' : sprintf('Unknown type (%s)', $type);
0 ignored issues
show
introduced by
The condition $type === null is always false.
Loading history...
150
        }
151
    }
152
}
153