Completed
Push — master ( 5fe3af...b86b7f )
by Propa
09:13
created

helpers.php ➔ phone_format()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.1481

Importance

Changes 5
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 5
b 0
f 0
nc 2
nop 3
dl 0
loc 12
ccs 4
cts 6
cp 0.6667
crap 2.1481
rs 9.4285
1
<?php
2
3
use Illuminate\Support\Facades\App;
4
use libphonenumber\PhoneNumberFormat;
5
6
if (!function_exists('phone_format')) {
7
	/**
8
	 * Formats a phone number and country for display.
9
	 *
10
	 * @param string   $phone
11
	 * @param string   $country
12
	 * @param int|null $format
13
	 * @return string
14
	 */
15
	function phone_format($phone, $country = null, $format = PhoneNumberFormat::INTERNATIONAL)
16
    	{
17 3
        	$lib = App::make('libphonenumber');
18
19 3
        	if (!$country) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $country of type string|null is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
20
        	  $country = App::getLocale();
21
        	}
22
23 3
        	$phoneNumber = $lib->parse($phone, $country);
24
25 3
        	return $lib->format($phoneNumber, $format);
26
    	}
27
}
28