Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Faker\Provider\en_US;
4
 
5
class PhoneNumber extends \Faker\Provider\PhoneNumber
6
{
7
    /**
8
     * @var array<int, string>
9
     */
10
    protected static $areaCodeRegexes = [
11
        2 => '(0[1-35-9]|1[02-9]|2[03-589]|3[149]|4[08]|5[1-46]|6[0279]|7[0269]|8[13])',
12
        3 => '(0[1-57-9]|1[02-9]|2[0135]|3[0-24679]|4[167]|5[12]|6[014]|8[056])',
13
        4 => '(0[124-9]|1[02-579]|2[3-5]|3[0245]|4[0235]|58|6[39]|7[0589]|8[04])',
14
        5 => '(0[1-57-9]|1[0235-8]|20|3[0149]|4[01]|5[19]|6[1-47]|7[013-5]|8[056])',
15
        6 => '(0[1-35-9]|1[024-9]|2[03689]|[34][016]|5[017]|6[0-279]|78|8[0-29])',
16
        7 => '(0[1-46-8]|1[2-9]|2[04-7]|3[1247]|4[037]|5[47]|6[02359]|7[02-59]|8[156])',
17
        8 => '(0[1-68]|1[02-8]|2[08]|3[0-28]|4[3578]|5[046-9]|6[02-5]|7[028])',
18
        9 => '(0[1346-9]|1[02-9]|2[0589]|3[0146-8]|4[0179]|5[12469]|7[0-389]|8[04-69])',
19
    ];
20
 
21
    /**
22
     * @see https://en.wikipedia.org/wiki/National_conventions_for_writing_telephone_numbers#United_States.2C_Canada.2C_and_other_NANP_countries
23
     */
24
    protected static $formats = [
25
        // International format
26
        '+1-{{areaCode}}-{{exchangeCode}}-####',
27
        '+1 ({{areaCode}}) {{exchangeCode}}-####',
28
        '+1-{{areaCode}}-{{exchangeCode}}-####',
29
        '+1.{{areaCode}}.{{exchangeCode}}.####',
30
        '+1{{areaCode}}{{exchangeCode}}####',
31
 
32
        // Standard formats
33
        '{{areaCode}}-{{exchangeCode}}-####',
34
        '({{areaCode}}) {{exchangeCode}}-####',
35
        '1-{{areaCode}}-{{exchangeCode}}-####',
36
        '{{areaCode}}.{{exchangeCode}}.####',
37
 
38
        '{{areaCode}}-{{exchangeCode}}-####',
39
        '({{areaCode}}) {{exchangeCode}}-####',
40
        '1-{{areaCode}}-{{exchangeCode}}-####',
41
        '{{areaCode}}.{{exchangeCode}}.####',
42
    ];
43
 
44
    protected static $formatsWithExtension = [
45
        '{{areaCode}}-{{exchangeCode}}-#### x###',
46
        '({{areaCode}}) {{exchangeCode}}-#### x###',
47
        '1-{{areaCode}}-{{exchangeCode}}-#### x###',
48
        '{{areaCode}}.{{exchangeCode}}.#### x###',
49
 
50
        '{{areaCode}}-{{exchangeCode}}-#### x####',
51
        '({{areaCode}}) {{exchangeCode}}-#### x####',
52
        '1-{{areaCode}}-{{exchangeCode}}-#### x####',
53
        '{{areaCode}}.{{exchangeCode}}.#### x####',
54
 
55
        '{{areaCode}}-{{exchangeCode}}-#### x#####',
56
        '({{areaCode}}) {{exchangeCode}}-#### x#####',
57
        '1-{{areaCode}}-{{exchangeCode}}-#### x#####',
58
        '{{areaCode}}.{{exchangeCode}}.#### x#####',
59
    ];
60
 
61
    protected static $e164Formats = [
62
        '+1{{areaCode}}{{exchangeCode}}####',
63
    ];
64
 
65
    /**
66
     * @see https://en.wikipedia.org/wiki/Toll-free_telephone_number#United_States
67
     */
68
    protected static $tollFreeAreaCodes = [
69
        800, 844, 855, 866, 877, 888,
70
    ];
71
    protected static $tollFreeFormats = [
72
        // Standard formats
73
        '{{tollFreeAreaCode}}-{{exchangeCode}}-####',
74
        '({{tollFreeAreaCode}}) {{exchangeCode}}-####',
75
        '1-{{tollFreeAreaCode}}-{{exchangeCode}}-####',
76
        '{{tollFreeAreaCode}}.{{exchangeCode}}.####',
77
    ];
78
 
79
    public function tollFreeAreaCode()
80
    {
81
        return self::randomElement(static::$tollFreeAreaCodes);
82
    }
83
 
84
    public function tollFreePhoneNumber()
85
    {
86
        $format = self::randomElement(static::$tollFreeFormats);
87
 
88
        return self::numerify($this->generator->parse($format));
89
    }
90
 
91
    /**
92
     * @return string
93
     *
94
     * @example '555-123-546 x123'
95
     */
96
    public function phoneNumberWithExtension()
97
    {
98
        return static::numerify($this->generator->parse(static::randomElement(static::$formatsWithExtension)));
99
    }
100
 
101
    /**
102
     * NPA-format area code
103
     *
104
     * @see https://en.wikipedia.org/wiki/North_American_Numbering_Plan#Numbering_system
105
     *
106
     * @return string
107
     */
108
    public static function areaCode()
109
    {
110
        $firstDigit = self::numberBetween(2, 9);
111
 
112
        return $firstDigit . self::regexify(self::$areaCodeRegexes[$firstDigit]);
113
    }
114
 
115
    /**
116
     * NXX-format central office exchange code
117
     *
118
     * @see https://en.wikipedia.org/wiki/North_American_Numbering_Plan#Numbering_system
119
     *
120
     * @return string
121
     */
122
    public static function exchangeCode()
123
    {
124
        $digits[] = self::numberBetween(2, 9);
125
        $digits[] = self::randomDigit();
126
 
127
        if ($digits[1] === 1) {
128
            $digits[] = self::randomDigitNot(1);
129
        } else {
130
            $digits[] = self::randomDigit();
131
        }
132
 
133
        return implode('', $digits);
134
    }
135
}