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\pt_BR;
4
 
5
class PhoneNumber extends \Faker\Provider\PhoneNumber
6
{
7
    protected static $landlineFormats = ['2###-####', '3###-####', '4###-####'];
8
 
9
    /**
10
     * Since december 2016 all mobile phone numbers in brazil begin with 9 and landlines 2, 3 or 4.
11
     *
12
     * @see http://www.anatel.gov.br/Portal/exibirPortalPaginaEspecial.do?org.apache.struts.taglib.html.TOKEN=9594e1d11fbc996d52bda44e608bb744&codItemCanal=1794&pastaSelecionada=2984
13
     */
14
    protected static $cellphoneFormats = ['9####-####'];
15
 
16
    /**
17
     * Generates a 2-digit area code not composed by zeroes.
18
     *
19
     * @see http://www.anatel.gov.br/legislacao/resolucoes/16-2001/383-resolucao-263.
20
     *
21
     * @return string
22
     */
23
    public static function areaCode()
24
    {
25
        $areaCodes = [
26
            '11', '12', '13', '14', '15', '16', '17', '18', '19', '21', '22', '24',
27
            '27', '28', '31', '32', '33', '34', '35', '37', '38', '41', '42', '43',
28
            '44', '45', '46', '47', '48', '49', '51', '53', '54', '55', '61', '62',
29
            '63', '64', '65', '66', '67', '68', '69', '71', '73', '74', '75', '77',
30
            '79', '81', '82', '83', '84', '85', '86', '87', '88', '89', '91', '92',
31
            '93', '94', '95', '96', '97', '98', '99',
32
        ];
33
 
34
        return self::randomElement($areaCodes);
35
    }
36
 
37
    /**
38
     * Generates a 9-digit cellphone number without formatting characters.
39
     *
40
     * @param bool $formatted [def: true] If it should return a formatted number or not.
41
     *
42
     * @return string
43
     */
44
    public static function cellphone($formatted = true)
45
    {
46
        $number = static::numerify(static::randomElement(static::$cellphoneFormats));
47
 
48
        if (!$formatted) {
49
            $number = strtr($number, ['-' => '']);
50
        }
51
 
52
        return $number;
53
    }
54
 
55
    /**
56
     * Generates an 9-digit landline number without formatting characters.
57
     *
58
     * @param bool $formatted [def: true] If it should return a formatted number or not.
59
     *
60
     * @return string
61
     */
62
    public static function landline($formatted = true)
63
    {
64
        $number = static::numerify(static::randomElement(static::$landlineFormats));
65
 
66
        if (!$formatted) {
67
            $number = strtr($number, ['-' => '']);
68
        }
69
 
70
        return $number;
71
    }
72
 
73
    /**
74
     * Randomizes between cellphone and landline numbers.
75
     *
76
     * @param bool $formatted [def: true] If it should return a formatted number or not.
77
     */
78
    public static function phone($formatted = true)
79
    {
80
        $options = static::randomElement([
81
            ['cellphone', false],
82
            ['cellphone', true],
83
            ['landline', null],
84
        ]);
85
 
86
        return call_user_func("static::{$options[0]}", $formatted, $options[1]);
87
    }
88
 
89
    /**
90
     * Generates a complete phone number.
91
     *
92
     * @param string $type      [def: landline] One of "landline" or "cellphone". Defaults to "landline" on invalid values.
93
     * @param bool   $formatted [def: true] If the number should be formatted or not.
94
     *
95
     * @return string
96
     */
97
    protected static function anyPhoneNumber($type, $formatted = true)
98
    {
99
        $area = static::areaCode();
100
        $number = ($type == 'cellphone') ?
101
            static::cellphone($formatted) :
102
            static::landline($formatted);
103
 
104
        return $formatted ? "($area) $number" : $area . $number;
105
    }
106
 
107
    /**
108
     * Concatenates {@link areaCode} and {@link cellphone} into a national cellphone number.
109
     *
110
     * @param bool $formatted [def: true] If it should return a formatted number or not.
111
     *
112
     * @return string
113
     */
114
    public static function cellphoneNumber($formatted = true)
115
    {
116
        return static::anyPhoneNumber('cellphone', $formatted);
117
    }
118
 
119
    /**
120
     * Concatenates {@link areaCode} and {@link landline} into a national landline number.
121
     *
122
     * @param bool $formatted [def: true] If it should return a formatted number or not.
123
     *
124
     * @return string
125
     */
126
    public static function landlineNumber($formatted = true)
127
    {
128
        return static::anyPhoneNumber('landline', $formatted);
129
    }
130
 
131
    /**
132
     * Randomizes between complete cellphone and landline numbers.
133
     */
134
    public function phoneNumber()
135
    {
136
        $method = static::randomElement(['cellphoneNumber', 'landlineNumber']);
137
 
138
        return call_user_func("static::$method", true);
139
    }
140
 
141
    /**
142
     * Randomizes between complete cellphone and landline numbers, cleared from formatting symbols.
143
     */
144
    public static function phoneNumberCleared()
145
    {
146
        $method = static::randomElement(['cellphoneNumber', 'landlineNumber']);
147
 
148
        return call_user_func("static::$method", false);
149
    }
150
}