@@ -4,16 +4,16 @@ |
||
4 | 4 | |
5 | 5 | class InvalidParameterException extends \Exception |
6 | 6 | { |
7 | - /** |
|
8 | - * Invalid parameters static constructor. |
|
9 | - * |
|
10 | - * @param array|Collection $parameters |
|
11 | - * @return static |
|
12 | - */ |
|
13 | - public static function parameters($parameters) |
|
14 | - { |
|
15 | - $parameters = Collection::make($parameters); |
|
7 | + /** |
|
8 | + * Invalid parameters static constructor. |
|
9 | + * |
|
10 | + * @param array|Collection $parameters |
|
11 | + * @return static |
|
12 | + */ |
|
13 | + public static function parameters($parameters) |
|
14 | + { |
|
15 | + $parameters = Collection::make($parameters); |
|
16 | 16 | |
17 | - return new static('Invalid phone validation parameters: "' . $parameters->implode(',') . '".'); |
|
18 | - } |
|
17 | + return new static('Invalid phone validation parameters: "' . $parameters->implode(',') . '".'); |
|
18 | + } |
|
19 | 19 | } |
20 | 20 | \ No newline at end of file |
@@ -4,17 +4,17 @@ |
||
4 | 4 | |
5 | 5 | class NumberParseException extends libNumberParseException |
6 | 6 | { |
7 | - /** |
|
8 | - * Country specification required static constructor. |
|
9 | - * |
|
10 | - * @param string $number |
|
11 | - * @return static |
|
12 | - */ |
|
13 | - public static function countryRequired($number) |
|
14 | - { |
|
15 | - return new static( |
|
16 | - libNumberParseException::INVALID_COUNTRY_CODE, |
|
17 | - 'Country specification for number "' . $number . '" required.' |
|
18 | - ); |
|
19 | - } |
|
7 | + /** |
|
8 | + * Country specification required static constructor. |
|
9 | + * |
|
10 | + * @param string $number |
|
11 | + * @return static |
|
12 | + */ |
|
13 | + public static function countryRequired($number) |
|
14 | + { |
|
15 | + return new static( |
|
16 | + libNumberParseException::INVALID_COUNTRY_CODE, |
|
17 | + 'Country specification for number "' . $number . '" required.' |
|
18 | + ); |
|
19 | + } |
|
20 | 20 | } |
21 | 21 | \ No newline at end of file |
@@ -2,14 +2,14 @@ |
||
2 | 2 | |
3 | 3 | class CountryCodeException extends \Exception |
4 | 4 | { |
5 | - /** |
|
6 | - * Invalid country code static constructor. |
|
7 | - * |
|
8 | - * @param string $country |
|
9 | - * @return static |
|
10 | - */ |
|
11 | - public static function invalid($country) |
|
12 | - { |
|
13 | - return new static('Invalid country code "' . $country . '".'); |
|
14 | - } |
|
5 | + /** |
|
6 | + * Invalid country code static constructor. |
|
7 | + * |
|
8 | + * @param string $country |
|
9 | + * @return static |
|
10 | + */ |
|
11 | + public static function invalid($country) |
|
12 | + { |
|
13 | + return new static('Invalid country code "' . $country . '".'); |
|
14 | + } |
|
15 | 15 | } |
@@ -2,14 +2,14 @@ |
||
2 | 2 | |
3 | 3 | class NumberFormatException extends \Exception |
4 | 4 | { |
5 | - /** |
|
6 | - * Invalid number format static constructor. |
|
7 | - * |
|
8 | - * @param string $format |
|
9 | - * @return static |
|
10 | - */ |
|
11 | - public static function invalid($format) |
|
12 | - { |
|
13 | - return new static('Invalid number format "' . $format . '".'); |
|
14 | - } |
|
5 | + /** |
|
6 | + * Invalid number format static constructor. |
|
7 | + * |
|
8 | + * @param string $format |
|
9 | + * @return static |
|
10 | + */ |
|
11 | + public static function invalid($format) |
|
12 | + { |
|
13 | + return new static('Invalid number format "' . $format . '".'); |
|
14 | + } |
|
15 | 15 | } |
16 | 16 | \ No newline at end of file |
@@ -10,63 +10,63 @@ |
||
10 | 10 | |
11 | 11 | class PhoneServiceProvider extends ServiceProvider |
12 | 12 | { |
13 | - /** |
|
14 | - * Bootstrap the application events. |
|
15 | - * |
|
16 | - * @return void |
|
17 | - */ |
|
18 | - public function boot() |
|
19 | - { |
|
20 | - $this->registerValidator(); |
|
13 | + /** |
|
14 | + * Bootstrap the application events. |
|
15 | + * |
|
16 | + * @return void |
|
17 | + */ |
|
18 | + public function boot() |
|
19 | + { |
|
20 | + $this->registerValidator(); |
|
21 | 21 | |
22 | - $this->registerRule(); |
|
23 | - } |
|
22 | + $this->registerRule(); |
|
23 | + } |
|
24 | 24 | |
25 | - /** |
|
26 | - * Register the service provider. |
|
27 | - * |
|
28 | - * @return void |
|
29 | - */ |
|
30 | - public function register() |
|
31 | - { |
|
32 | - $this->app->singleton('libphonenumber', function ($app) { |
|
33 | - return PhoneNumberUtil::getInstance(); |
|
34 | - }); |
|
25 | + /** |
|
26 | + * Register the service provider. |
|
27 | + * |
|
28 | + * @return void |
|
29 | + */ |
|
30 | + public function register() |
|
31 | + { |
|
32 | + $this->app->singleton('libphonenumber', function ($app) { |
|
33 | + return PhoneNumberUtil::getInstance(); |
|
34 | + }); |
|
35 | 35 | |
36 | - $this->app->alias('libphonenumber', PhoneNumberUtil::class); |
|
37 | - } |
|
36 | + $this->app->alias('libphonenumber', PhoneNumberUtil::class); |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * Register the "phone" validator. |
|
41 | - */ |
|
42 | - protected function registerValidator() |
|
43 | - { |
|
44 | - $extend = static::canUseDependentValidation() ? 'extendDependent' : 'extend'; |
|
39 | + /** |
|
40 | + * Register the "phone" validator. |
|
41 | + */ |
|
42 | + protected function registerValidator() |
|
43 | + { |
|
44 | + $extend = static::canUseDependentValidation() ? 'extendDependent' : 'extend'; |
|
45 | 45 | |
46 | - $this->app['validator']->{$extend}('phone', Validation\Phone::class . '@validate'); |
|
47 | - } |
|
46 | + $this->app['validator']->{$extend}('phone', Validation\Phone::class . '@validate'); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Register the "phone" rule macro. |
|
51 | - */ |
|
52 | - protected function registerRule() |
|
53 | - { |
|
54 | - if (class_exists('Illuminate\Validation\Rule') && class_uses(Rule::class, Macroable::class)) { |
|
55 | - Rule::macro('phone', function () { |
|
56 | - return new Rules\Phone; |
|
57 | - }); |
|
58 | - } |
|
59 | - } |
|
49 | + /** |
|
50 | + * Register the "phone" rule macro. |
|
51 | + */ |
|
52 | + protected function registerRule() |
|
53 | + { |
|
54 | + if (class_exists('Illuminate\Validation\Rule') && class_uses(Rule::class, Macroable::class)) { |
|
55 | + Rule::macro('phone', function () { |
|
56 | + return new Rules\Phone; |
|
57 | + }); |
|
58 | + } |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * Determine whether we can register a dependent validator. |
|
63 | - * |
|
64 | - * @return bool |
|
65 | - */ |
|
66 | - public static function canUseDependentValidation() |
|
67 | - { |
|
68 | - $validator = new ReflectionClass('\Illuminate\Validation\Factory'); |
|
61 | + /** |
|
62 | + * Determine whether we can register a dependent validator. |
|
63 | + * |
|
64 | + * @return bool |
|
65 | + */ |
|
66 | + public static function canUseDependentValidation() |
|
67 | + { |
|
68 | + $validator = new ReflectionClass('\Illuminate\Validation\Factory'); |
|
69 | 69 | |
70 | - return $validator->hasMethod('extendDependent'); |
|
71 | - } |
|
70 | + return $validator->hasMethod('extendDependent'); |
|
71 | + } |
|
72 | 72 | } |
@@ -5,31 +5,31 @@ |
||
5 | 5 | |
6 | 6 | trait ParsesCountries |
7 | 7 | { |
8 | - /** |
|
9 | - * Determine whether the given country code is valid. |
|
10 | - * |
|
11 | - * @param string $country |
|
12 | - * @return bool |
|
13 | - */ |
|
14 | - public static function isValidCountryCode($country) |
|
15 | - { |
|
16 | - return ISO3166::isValid($country); |
|
17 | - } |
|
8 | + /** |
|
9 | + * Determine whether the given country code is valid. |
|
10 | + * |
|
11 | + * @param string $country |
|
12 | + * @return bool |
|
13 | + */ |
|
14 | + public static function isValidCountryCode($country) |
|
15 | + { |
|
16 | + return ISO3166::isValid($country); |
|
17 | + } |
|
18 | 18 | |
19 | - /** |
|
20 | - * Parse the provided phone countries to a valid array. |
|
21 | - * |
|
22 | - * @param string|array $countries |
|
23 | - * @return array |
|
24 | - */ |
|
25 | - protected function parseCountries($countries) |
|
26 | - { |
|
27 | - return Collection::make(is_array($countries) ? $countries : func_get_args()) |
|
28 | - ->map(function ($country) { |
|
29 | - return strtoupper($country); |
|
30 | - }) |
|
31 | - ->filter(function ($value) { |
|
32 | - return static::isValidCountryCode($value); |
|
33 | - })->toArray(); |
|
34 | - } |
|
19 | + /** |
|
20 | + * Parse the provided phone countries to a valid array. |
|
21 | + * |
|
22 | + * @param string|array $countries |
|
23 | + * @return array |
|
24 | + */ |
|
25 | + protected function parseCountries($countries) |
|
26 | + { |
|
27 | + return Collection::make(is_array($countries) ? $countries : func_get_args()) |
|
28 | + ->map(function ($country) { |
|
29 | + return strtoupper($country); |
|
30 | + }) |
|
31 | + ->filter(function ($value) { |
|
32 | + return static::isValidCountryCode($value); |
|
33 | + })->toArray(); |
|
34 | + } |
|
35 | 35 | } |
36 | 36 | \ No newline at end of file |
@@ -7,74 +7,74 @@ |
||
7 | 7 | |
8 | 8 | trait ParsesTypes |
9 | 9 | { |
10 | - /** |
|
11 | - * Array of available phone types. |
|
12 | - * |
|
13 | - * @var array |
|
14 | - */ |
|
15 | - protected static $types; |
|
10 | + /** |
|
11 | + * Array of available phone types. |
|
12 | + * |
|
13 | + * @var array |
|
14 | + */ |
|
15 | + protected static $types; |
|
16 | 16 | |
17 | - /** |
|
18 | - * Determine whether the given type is valid. |
|
19 | - * |
|
20 | - * @param string $type |
|
21 | - * @return bool |
|
22 | - */ |
|
23 | - public static function isValidType($type) |
|
24 | - { |
|
25 | - return ! empty(static::parseTypes($type)); |
|
26 | - } |
|
17 | + /** |
|
18 | + * Determine whether the given type is valid. |
|
19 | + * |
|
20 | + * @param string $type |
|
21 | + * @return bool |
|
22 | + */ |
|
23 | + public static function isValidType($type) |
|
24 | + { |
|
25 | + return ! empty(static::parseTypes($type)); |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * Parse a phone type into constant's value. |
|
30 | - * |
|
31 | - * @param string|array $types |
|
32 | - * @return array |
|
33 | - */ |
|
34 | - protected static function parseTypes($types) |
|
35 | - { |
|
36 | - static::loadTypes(); |
|
28 | + /** |
|
29 | + * Parse a phone type into constant's value. |
|
30 | + * |
|
31 | + * @param string|array $types |
|
32 | + * @return array |
|
33 | + */ |
|
34 | + protected static function parseTypes($types) |
|
35 | + { |
|
36 | + static::loadTypes(); |
|
37 | 37 | |
38 | - return Collection::make(is_array($types) ? $types : func_get_args()) |
|
39 | - ->map(function ($type) { |
|
40 | - // If the type equals a constant's value, just return it. |
|
41 | - if (in_array($type, static::$types, true)) { |
|
42 | - return $type; |
|
43 | - } |
|
38 | + return Collection::make(is_array($types) ? $types : func_get_args()) |
|
39 | + ->map(function ($type) { |
|
40 | + // If the type equals a constant's value, just return it. |
|
41 | + if (in_array($type, static::$types, true)) { |
|
42 | + return $type; |
|
43 | + } |
|
44 | 44 | |
45 | - // Otherwise we'll assume the type is the constant's name. |
|
46 | - return Arr::get(static::$types, strtoupper($type)); |
|
47 | - }) |
|
48 | - ->reject(function ($value) { |
|
49 | - return is_null($value) || $value === false; |
|
50 | - })->toArray(); |
|
51 | - } |
|
45 | + // Otherwise we'll assume the type is the constant's name. |
|
46 | + return Arr::get(static::$types, strtoupper($type)); |
|
47 | + }) |
|
48 | + ->reject(function ($value) { |
|
49 | + return is_null($value) || $value === false; |
|
50 | + })->toArray(); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Parse a phone type into its string representation. |
|
55 | - * |
|
56 | - * @param string|array $types |
|
57 | - * @return array |
|
58 | - */ |
|
59 | - protected static function parseTypesAsStrings($types) |
|
60 | - { |
|
61 | - static::loadTypes(); |
|
53 | + /** |
|
54 | + * Parse a phone type into its string representation. |
|
55 | + * |
|
56 | + * @param string|array $types |
|
57 | + * @return array |
|
58 | + */ |
|
59 | + protected static function parseTypesAsStrings($types) |
|
60 | + { |
|
61 | + static::loadTypes(); |
|
62 | 62 | |
63 | - return array_keys( |
|
64 | - array_intersect( |
|
65 | - static::$types, |
|
66 | - static::parseTypes($types) |
|
67 | - ) |
|
68 | - ); |
|
69 | - } |
|
63 | + return array_keys( |
|
64 | + array_intersect( |
|
65 | + static::$types, |
|
66 | + static::parseTypes($types) |
|
67 | + ) |
|
68 | + ); |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * Load all available formats once. |
|
73 | - */ |
|
74 | - private static function loadTypes() |
|
75 | - { |
|
76 | - if (! static::$types) { |
|
77 | - static::$types = with(new ReflectionClass(PhoneNumberType::class))->getConstants(); |
|
78 | - } |
|
79 | - } |
|
71 | + /** |
|
72 | + * Load all available formats once. |
|
73 | + */ |
|
74 | + private static function loadTypes() |
|
75 | + { |
|
76 | + if (! static::$types) { |
|
77 | + static::$types = with(new ReflectionClass(PhoneNumberType::class))->getConstants(); |
|
78 | + } |
|
79 | + } |
|
80 | 80 | } |
81 | 81 | \ No newline at end of file |
@@ -6,50 +6,50 @@ |
||
6 | 6 | |
7 | 7 | trait ParsesFormats |
8 | 8 | { |
9 | - /** |
|
10 | - * Array of available phone formats. |
|
11 | - * |
|
12 | - * @var array |
|
13 | - */ |
|
14 | - protected static $formats; |
|
9 | + /** |
|
10 | + * Array of available phone formats. |
|
11 | + * |
|
12 | + * @var array |
|
13 | + */ |
|
14 | + protected static $formats; |
|
15 | 15 | |
16 | - /** |
|
17 | - * Determine whether the given format is valid. |
|
18 | - * |
|
19 | - * @param string $format |
|
20 | - * @return bool |
|
21 | - */ |
|
22 | - public static function isValidFormat($format) |
|
23 | - { |
|
24 | - return ! is_null(static::parseFormat($format)); |
|
25 | - } |
|
16 | + /** |
|
17 | + * Determine whether the given format is valid. |
|
18 | + * |
|
19 | + * @param string $format |
|
20 | + * @return bool |
|
21 | + */ |
|
22 | + public static function isValidFormat($format) |
|
23 | + { |
|
24 | + return ! is_null(static::parseFormat($format)); |
|
25 | + } |
|
26 | 26 | |
27 | - /** |
|
28 | - * Parse a phone format. |
|
29 | - * |
|
30 | - * @param string $format |
|
31 | - * @return string |
|
32 | - */ |
|
33 | - protected static function parseFormat($format) |
|
34 | - { |
|
35 | - static::loadFormats(); |
|
27 | + /** |
|
28 | + * Parse a phone format. |
|
29 | + * |
|
30 | + * @param string $format |
|
31 | + * @return string |
|
32 | + */ |
|
33 | + protected static function parseFormat($format) |
|
34 | + { |
|
35 | + static::loadFormats(); |
|
36 | 36 | |
37 | - // If the format equals a constant's value, just return it. |
|
38 | - if (in_array($format, static::$formats, true)) { |
|
39 | - return $format; |
|
40 | - } |
|
37 | + // If the format equals a constant's value, just return it. |
|
38 | + if (in_array($format, static::$formats, true)) { |
|
39 | + return $format; |
|
40 | + } |
|
41 | 41 | |
42 | - // Otherwise we'll assume the format is the constant's name. |
|
43 | - return Arr::get(static::$formats, strtoupper($format)); |
|
44 | - } |
|
42 | + // Otherwise we'll assume the format is the constant's name. |
|
43 | + return Arr::get(static::$formats, strtoupper($format)); |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Load all available formats once. |
|
48 | - */ |
|
49 | - private static function loadFormats() |
|
50 | - { |
|
51 | - if (! static::$formats) { |
|
52 | - static::$formats = with(new ReflectionClass(PhoneNumberFormat::class))->getConstants(); |
|
53 | - } |
|
54 | - } |
|
46 | + /** |
|
47 | + * Load all available formats once. |
|
48 | + */ |
|
49 | + private static function loadFormats() |
|
50 | + { |
|
51 | + if (! static::$formats) { |
|
52 | + static::$formats = with(new ReflectionClass(PhoneNumberFormat::class))->getConstants(); |
|
53 | + } |
|
54 | + } |
|
55 | 55 | } |
56 | 56 | \ No newline at end of file |
@@ -3,22 +3,22 @@ |
||
3 | 3 | use Propaganistas\LaravelPhone\PhoneNumber; |
4 | 4 | |
5 | 5 | if (! function_exists('phone')) { |
6 | - /** |
|
7 | - * Get a PhoneNumber instance or a formatted string. |
|
8 | - * |
|
9 | - * @param string $number |
|
10 | - * @param string|array $country |
|
11 | - * @param string $format |
|
12 | - * @return string|Propaganistas\LaravelPhone\PhoneNumber |
|
13 | - */ |
|
14 | - function phone($number, $country = [], $format = null) |
|
15 | - { |
|
16 | - $phone = PhoneNumber::make($number, $country); |
|
6 | + /** |
|
7 | + * Get a PhoneNumber instance or a formatted string. |
|
8 | + * |
|
9 | + * @param string $number |
|
10 | + * @param string|array $country |
|
11 | + * @param string $format |
|
12 | + * @return string|Propaganistas\LaravelPhone\PhoneNumber |
|
13 | + */ |
|
14 | + function phone($number, $country = [], $format = null) |
|
15 | + { |
|
16 | + $phone = PhoneNumber::make($number, $country); |
|
17 | 17 | |
18 | - if (! is_null($format)) { |
|
19 | - return $phone->format($format); |
|
20 | - } |
|
18 | + if (! is_null($format)) { |
|
19 | + return $phone->format($format); |
|
20 | + } |
|
21 | 21 | |
22 | - return $phone; |
|
23 | - } |
|
22 | + return $phone; |
|
23 | + } |
|
24 | 24 | } |