PhoneNumber   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 253
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 230
dl 0
loc 253
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A phoneNumber() 0 3 1
A e164PhoneNumber() 0 3 1
A imei() 0 6 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace DummyGenerator\Core;
6
7
use DummyGenerator\Definitions\Extension\Awareness\LuhnCalculatorAwareExtensionInterface;
8
use DummyGenerator\Definitions\Extension\Awareness\LuhnCalculatorAwareExtensionTrait;
9
use DummyGenerator\Definitions\Extension\Awareness\RandomizerAwareExtensionInterface;
10
use DummyGenerator\Definitions\Extension\Awareness\RandomizerAwareExtensionTrait;
11
use DummyGenerator\Definitions\Extension\Awareness\ReplacerAwareExtensionInterface;
12
use DummyGenerator\Definitions\Extension\Awareness\ReplacerAwareExtensionTrait;
13
use DummyGenerator\Definitions\Extension\PhoneNumberExtensionInterface;
14
15
class PhoneNumber implements
16
    PhoneNumberExtensionInterface,
17
    RandomizerAwareExtensionInterface,
18
    LuhnCalculatorAwareExtensionInterface,
19
    ReplacerAwareExtensionInterface
20
{
21
    use RandomizerAwareExtensionTrait;
22
    use LuhnCalculatorAwareExtensionTrait;
23
    use ReplacerAwareExtensionTrait;
24
25
    /** @var string[] */
26
    protected array $formats = ['###-###-###'];
27
28
    /**
29
     * @var string[]
30
     *
31
     * @see https://github.com/giggsey/libphonenumber-for-php/blob/master/src/CountryCodeToRegionCodeMap.php
32
     * @see https://libphonenumber.appspot.com/phonenumberparser?number=%2B4576597442
33
     */
34
    protected array $e164Formats = [
35
        '+1##########',
36
        '+7##########',
37
        '+20##########',
38
        '+27##########',
39
        '+30##########',
40
        '+31##########',
41
        '+32#########',
42
        '+33#########',
43
        '+34#########',
44
        '+36#########',
45
        '+39##########',
46
        '+40#########',
47
        '+41#########',
48
        '+43##########',
49
        '+44##########',
50
        '+45########',
51
        '+46##########',
52
        '+47########',
53
        '+48##########',
54
        '+49##########',
55
        '+51#########',
56
        '+52##########',
57
        '+53##########',
58
        '+54##########',
59
        '+55#########',
60
        '+56##########',
61
        '+57##########',
62
        '+58##########',
63
        '+60##########',
64
        '+61##########',
65
        '+62##########',
66
        '+63##########',
67
        '+64##########',
68
        '+65##########',
69
        '+66##########',
70
        '+81##########',
71
        '+82##########',
72
        '+84##########',
73
        '+86##########',
74
        '+90##########',
75
        '+91##########',
76
        '+92##########',
77
        '+93#########',
78
        '+94#########',
79
        '+95##########',
80
        '+98##########',
81
        '+211#########',
82
        '+212#########',
83
        '+213#########',
84
        '+216########',
85
        '+218#########',
86
        '+220#######',
87
        '+221#########',
88
        '+222########',
89
        '+223########',
90
        '+224#########',
91
        '+225##########',
92
        '+226########',
93
        '+227########',
94
        '+228########',
95
        '+229########',
96
        '+230########',
97
        '+231#########',
98
        '+232########',
99
        '+233#########',
100
        '+234##########',
101
        '+235########',
102
        '+236########',
103
        '+237#########',
104
        '+238#######',
105
        '+239#######',
106
        '+240#########',
107
        '+241########',
108
        '+242#########',
109
        '+243#########',
110
        '+244#########',
111
        '+245#########',
112
        '+246#######',
113
        '+247######',
114
        '+248#######',
115
        '+249#########',
116
        '+250#########',
117
        '+251#########',
118
        '+252#########',
119
        '+253########',
120
        '+254##########',
121
        '+255#########',
122
        '+256#########',
123
        '+257########',
124
        '+258#########',
125
        '+260#########',
126
        '+261#########',
127
        '+262#########',
128
        '+263##########',
129
        '+264#########',
130
        '+265#########',
131
        '+266########',
132
        '+267##########',
133
        '+268#########',
134
        '+269#######',
135
        '+290#####',
136
        '+291#######',
137
        '+297#######',
138
        '+298######',
139
        '+299######',
140
        '+350########',
141
        '+351#########',
142
        '+352##########',
143
        '+353##########',
144
        '+354#########',
145
        '+355#########',
146
        '+356########',
147
        '+357########',
148
        '+358##########',
149
        '+359#########',
150
        '+370########',
151
        '+371########',
152
        '+372##########',
153
        '+373########',
154
        '+374########',
155
        '+375##########',
156
        '+376#########',
157
        '+377#########',
158
        '+378##########',
159
        '+380##########',
160
        '+381##########',
161
        '+382#########',
162
        '+383#########',
163
        '+385#########',
164
        '+386########',
165
        '+387#########',
166
        '+389########',
167
        '+420#########',
168
        '+421#########',
169
        '+423#########',
170
        '+500#####',
171
        '+501#######',
172
        '+502########',
173
        '+503########',
174
        '+504########',
175
        '+505########',
176
        '+506########',
177
        '+507##########',
178
        '+508#########',
179
        '+509########',
180
        '+590#########',
181
        '+591#########',
182
        '+592#######',
183
        '+593##########',
184
        '+594#########',
185
        '+595##########',
186
        '+596#########',
187
        '+597#######',
188
        '+598##########',
189
        '+599########',
190
        '+670########',
191
        '+672######',
192
        '+673#######',
193
        '+674#######',
194
        '+675########',
195
        '+676#######',
196
        '+677#######',
197
        '+678#######',
198
        '+679#######',
199
        '+680#######',
200
        '+681#########',
201
        '+682#####',
202
        '+683#######',
203
        '+685##########',
204
        '+686########',
205
        '+687######',
206
        '+688#######',
207
        '+689#########',
208
        '+690#######',
209
        '+691#######',
210
        '+692#######',
211
        '+800########',
212
        '+808########',
213
        '+850##########',
214
        '+852#########',
215
        '+853########',
216
        '+855##########',
217
        '+856##########',
218
        '+870#########',
219
        '+878############',
220
        '+880##########',
221
        '+881#########',
222
        '+882##########',
223
        '+883#########',
224
        '+886##########',
225
        '+888###########',
226
        '+960##########',
227
        '+961########',
228
        '+962#########',
229
        '+963#########',
230
        '+964##########',
231
        '+965########',
232
        '+966##########',
233
        '+967#########',
234
        '+968#########',
235
        '+970##########',
236
        '+971##########',
237
        '+972##########',
238
        '+973########',
239
        '+974########',
240
        '+975########',
241
        '+976##########',
242
        '+977##########',
243
        '+979#########',
244
        '+992#########',
245
        '+993########',
246
        '+994#########',
247
        '+995#########',
248
        '+996#########',
249
        '+998#########',
250
    ];
251
252 1
    public function phoneNumber(): string
253
    {
254 1
        return $this->replacer->numerify($this->randomizer->randomElement($this->formats));
255
    }
256
257 1
    public function e164PhoneNumber(): string
258
    {
259 1
        return $this->replacer->numerify($this->randomizer->randomElement($this->e164Formats));
260
    }
261
262 1
    public function imei(): string
263
    {
264 1
        $imei = $this->replacer->numerify('##############');
265 1
        $imei .= $this->luhnCalculator->computeCheckDigit($imei);
266
267 1
        return $imei;
268
    }
269
}
270