Completed
Push — master ( 7337e3...7741a0 )
by Propa
03:25
created

helpers.php ➔ phone_format()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 3
dl 0
loc 4
ccs 0
cts 1
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
use Illuminate\Support\Facades\App;
4
use libphonenumber\PhoneNumberFormat;
5
6
if (! function_exists('phone_format')) {
7
    /**
8
     * Get the PhoneNumberUtil or format a phone number for display.
9
     *
10
     * @return \libphonenumber\PhoneNumberUtil|string
11
     */
12
    function phone()
13
    {
14 2
        $lib = App::make('libphonenumber');
15
16 2
        if (! $arguments = func_get_args()) {
17 3
            return $lib;
18
        }
19
20 2
        $phone = $arguments[0];
21 2
        $country = isset($arguments[1]) ? $arguments[1] : App::getLocale();
22 2
        $format = isset($arguments[2]) ? $arguments[2] : PhoneNumberFormat::INTERNATIONAL;
23
24 2
        return $lib->format(
25 2
            $lib->parse($phone, $country),
26
            $format
27 2
        );
28
    }
29
}
30
31
if (! function_exists('phone_format')) {
32
    /**
33
     * Formats a phone number and country for display.
34
     *
35
     * @param string   $phone
36
     * @param string   $country
37
     * @param int|null $format
38
     * @return string
39
     *
40
     * @deprecated 2.8.0
41
     */
42
    function phone_format($phone, $country = null, $format = PhoneNumberFormat::INTERNATIONAL)
43
    {
44
        return phone($phone, $country, $format);
45
    }
46
}
47