|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Illuminate\Support\Facades\App; |
|
4
|
|
|
use libphonenumber\PhoneNumberFormat; |
|
5
|
|
|
use Illuminate\Support\Facades\Validator; |
|
6
|
|
|
|
|
7
|
|
|
if (! function_exists('phone')) { |
|
8
|
|
|
/** |
|
9
|
|
|
* Get the PhoneNumberUtil or format a phone number for display. |
|
10
|
|
|
* |
|
11
|
|
|
* @return \libphonenumber\PhoneNumberUtil|string |
|
12
|
|
|
*/ |
|
13
|
|
|
function phone() |
|
14
|
3 |
|
{ |
|
15
|
|
|
$lib = App::make('libphonenumber'); |
|
16
|
3 |
|
|
|
17
|
3 |
|
if (! $arguments = func_get_args()) { |
|
18
|
|
|
return $lib; |
|
19
|
|
|
} |
|
20
|
3 |
|
|
|
21
|
3 |
|
$phone = $arguments[0]; |
|
22
|
3 |
|
|
|
23
|
|
|
$countries = isset($arguments[1]) ? (is_array($arguments[1]) ? $arguments[1] : [$arguments[1]]) : []; |
|
24
|
3 |
|
|
|
25
|
3 |
|
$format = isset($arguments[2]) ? $arguments[2] : PhoneNumberFormat::INTERNATIONAL; |
|
26
|
2 |
|
|
|
27
|
1 |
|
$validator = null; |
|
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
for($i = 0; $i < sizeof($countries); $i++) |
|
|
|
|
|
|
30
|
|
|
{ |
|
31
|
|
|
if($countries[$i] === null) |
|
32
|
|
|
{ |
|
33
|
|
|
return $lib->format( |
|
34
|
|
|
$lib->parse($phone, App::getLocale()), |
|
35
|
|
|
$format |
|
36
|
|
|
); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
$validator = Validator::make(['phone' => $phone], [ |
|
40
|
|
|
'phone' => 'required|phone:' . $countries[$i], |
|
41
|
|
|
]); |
|
42
|
|
|
|
|
43
|
|
|
if (!$validator->fails()) { |
|
44
|
|
|
return $lib->format( |
|
45
|
|
|
$lib->parse($phone, $countries[$i]), |
|
46
|
|
|
$format |
|
47
|
|
|
); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
return $lib; |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
if (! function_exists('phone_format')) { |
|
56
|
|
|
/** |
|
57
|
|
|
* Formats a phone number and country for display. |
|
58
|
|
|
* |
|
59
|
|
|
* @param string $phone |
|
60
|
|
|
* @param string|string[] $countries |
|
61
|
|
|
* @param int|null $format |
|
62
|
|
|
* @return string |
|
63
|
|
|
* |
|
64
|
|
|
* @deprecated 2.8.0 |
|
65
|
|
|
*/ |
|
66
|
|
|
function phone_format($phone, $countries = null, $format = PhoneNumberFormat::INTERNATIONAL) |
|
67
|
|
|
{ |
|
68
|
|
|
return phone($phone, $countries, $format); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.