Completed
Push — master ( 770502...b70235 )
by Propa
17:15
created

LaravelPhoneServiceProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 6
Bugs 0 Features 0
Metric Value
c 6
b 0
f 0
dl 0
loc 40
ccs 12
cts 12
cp 1
rs 10
wmc 4
lcom 1
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 6 2
A register() 0 8 1
A canUseDependentValidation() 0 6 1
1
<?php namespace Propaganistas\LaravelPhone;
2
3
use Illuminate\Support\ServiceProvider;
4
use libphonenumber\PhoneNumberUtil;
5
use ReflectionClass;
6
7
class LaravelPhoneServiceProvider extends ServiceProvider
8
{
9
    /**
10
     * Bootstrap the application events.
11
     *
12
     * @return void
13
     */
14 36
    public function boot()
15
    {
16 36
        $extend = static::canUseDependentValidation() ? 'extendDependent' : 'extend';
17
18 36
        $this->app['validator']->{$extend}('phone', 'Propaganistas\LaravelPhone\PhoneValidator@validatePhone');
19 36
    }
20
21
    /**
22
     * Register the service provider.
23
     *
24
     * @return void
25
     */
26
    public function register()
27
    {
28 36
        $this->app->singleton('libphonenumber', function ($app) {
29 33
            return PhoneNumberUtil::getInstance();
30 36
        });
31
32 36
        $this->app->alias('libphonenumber', 'libphonenumber\PhoneNumberUtil');
33 36
    }
34
35
    /**
36
     * Determine whether we can register a dependent validator.
37
     *
38
     * @return bool
39
     */
40 36
    public static function canUseDependentValidation()
41
    {
42 36
        $validator = new ReflectionClass('\Illuminate\Validation\Factory');
43
44 36
        return $validator->hasMethod('extendDependent');
45
    }
46
}
47