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