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

canUseDependentValidation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 6
ccs 3
cts 3
cp 1
crap 1
rs 9.4285
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