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

helpers.php ➔ phone()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 10
nc 5
nop 0
dl 0
loc 17
ccs 9
cts 9
cp 1
crap 4
rs 9.2
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