PhoneNumber.php
4.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
namespace Faker\Provider\de_DE;
class PhoneNumber extends \Faker\Provider\PhoneNumber
{
/**
* @var array<int, string>
*/
protected static $areaCodeRegexes = [
2 => '(0[0-389]|0[4-6][1-68]|1[124]|1[0-9][0-9]|2[18]|2[0-9][1-9]|3[14]|3[0-35-9][0-9]|4[1]|4[02-8][0-9]|5[1]|5[02-9][0-9]|6[1]|6[02-9][0-9]|7[1]|7[2-7][0-9]|8[1]|8[02-7][0-9]|9[1]|9[02-9][0-9])',
3 => '(0|3[15]|3[02-46-9][1-9]|3[02-46-9][02-9][0-9]|4[015]|4[2-4679][1-8]|4[2-4679][02-9][0-9]|5[15]|5[02-46-9][1-9]|5[02-46-9][02-9][0-9]|6[15]|6[02-46-9][1-9]|6[02-46-9][02-9][0-9]|7[15]|7[2-467][1-7]|7[2-467][02-689][0-9]|8[15]|8[2-46-8][013-9]|8[2-46-8][02-9][0-9]|9[15]|9[02-46-9][1-9]|9[02-46-9][02-9][0-9])',
4 => '(0|1[02-9][0-9]|2[1]|2[02-9][0-9]|3[1]|3[02-9][0-9]|4[1]|4[0-9][0-9]|5[1]|5[02-6][0-9]|6[1]|6[02-8][0-9]|7[1]|7[02-79][0-9]|8[1]|8[02-9][0-9]|9[1]|9[02-7][0-9])',
5 => '(0[2-8][0-9]|1[1]|1[02-9][0-9]|2[1]|2[02-9][1-9]|3[1]|3[02-8][0-9]|4[1]|4[02-9][1-9]|5[1]|5[02-9][0-9]|6[1]|6[02-9][0-9]|7[1]|7[02-7][1-9]|8[1]|8[02-8][0-9]|9[1]|9[0-7][1-9])',
6 => '(0[02-9][0-9]|1[1]|1[02-9][0-9]|2[1]|2[02-9][0-9]|3[1]|3[02-9][0-9]|4[1]|4[0-8][0-9]|5[1]|5[02-9][0-9]|6[1]|6[2-9][0-9]|7[1]|7[02-8][1-9]|8[1]|8[02-9][1-9]|9)',
7 => '(0[2-8][1-6]|1[1]|1[2-9][0-9]|2[1]|2[0-7][0-9]|3[1]|3[02-9][0-9]|4[1]|4[0-8][0-9]|5[1]|5[02-8][0-9]|6[1]|6[02-8][0-9]|7[1]|7[02-7][0-9]|8[1]|8[02-5][1-9]|9[1]|9[03-7][0-9])',
8 => '(0[2-9][0-9]|1[1]|1[02-79][0-9]|2[1]|2[02-9][0-9]|3[1]|3[02-9][0-9]|4[1]|4[02-6][0-9]|5[1]|5[02-9][0-9]|6[1]|6[2-8][0-9]|7[1]|7[02-8][1-9]|8[1]|8[02-6][0-9]|9)',
9 => '(0[6]|0[07-9][0-9]|1[1]|1[02-9][0-9]|2[1]|2[02-9][0-9]|3[1]|3[02-9][0-9]|4[1]|4[02-9][0-9]|5[1]|5[02-7][0-9]|6[1]|6[02-8][1-9]|7[1]|7[02-467][0-9]|8[1]|8[02-7][0-9]|9[1]|9[02-7][0-9])',
];
/**
* @see https://en.wikipedia.org/wiki/National_conventions_for_writing_telephone_numbers#Germany
* @see https://www.itu.int/oth/T0202000051/en
* @see https://en.wikipedia.org/wiki/Telephone_numbers_in_Germany
*/
protected static $formats = [
// International format
'+49 {{areaCode}} #######',
'+49 {{areaCode}} ### ####',
'+49 (0{{areaCode}}) #######',
'+49 (0{{areaCode}}) ### ####',
'+49{{areaCode}}#######',
'+49{{areaCode}}### ####',
// Standard formats
'0{{areaCode}} ### ####',
'0{{areaCode}} #######',
'(0{{areaCode}}) ### ####',
'(0{{areaCode}}) #######',
];
protected static $e164Formats = [
'+49{{areaCode}}#######',
];
/**
* @see https://en.wikipedia.org/wiki/Toll-free_telephone_number
*/
protected static $tollFreeAreaCodes = [
800,
];
protected static $tollFreeFormats = [
// Standard formats
'0{{tollFreeAreaCode}} ### ####',
'(0{{tollFreeAreaCode}}) ### ####',
'+49{{tollFreeAreaCode}} ### ####',
];
public function tollFreeAreaCode()
{
return self::randomElement(static::$tollFreeAreaCodes);
}
public function tollFreePhoneNumber()
{
$format = self::randomElement(static::$tollFreeFormats);
return self::numerify($this->generator->parse($format));
}
protected static $mobileCodes = [
1511, 1512, 1514, 1515, 1516, 1517,
1520, 1521, 1522, 1523, 1525, 1526, 1529,
1570, 1573, 1575, 1577, 1578, 1579,
1590,
];
protected static $mobileFormats = [
'+49{{mobileCode}}#######',
'+49 {{mobileCode}} ### ####',
'0{{mobileCode}}#######',
'0{{mobileCode}} ### ####',
'0 {{mobileCode}} ### ####',
];
/**
* @see https://en.wikipedia.org/wiki/List_of_dialling_codes_in_Germany
*
* @return string
*/
public static function areaCode()
{
$firstDigit = self::numberBetween(2, 9);
return $firstDigit . self::regexify(self::$areaCodeRegexes[$firstDigit]);
}
/**
* Generate a code for a mobile number.
*
* @internal Used to generate mobile numbers.
*
* @return string
*/
public static function mobileCode()
{
return static::randomElement(static::$mobileCodes);
}
/**
* Generate a mobile number.
*
* @example A mobile number: '015111234567'
* @example A mobile number with spaces: '01511 123 4567'
* @example A mobile number with international code prefix: '+4915111234567'
* @example A mobile number with international code prefix and spaces: '+49 1511 123 4567'
*
* @return string
*/
public function mobileNumber()
{
return ltrim(static::numerify($this->generator->parse(
static::randomElement(static::$mobileFormats),
)));
}
}