Completed
Push — master ( 5fb9ec...7328ed )
by ARCANEDEV
04:25
created

ValidatorServiceProvider   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 12.5%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 86
ccs 3
cts 24
cp 0.125
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A boot() 0 4 1
A register() 0 4 1
A registerUserValidators() 0 12 1
A extendValidator() 0 7 2
1
<?php namespace Arcanesoft\Auth\Providers;
2
3
use Arcanedev\Support\ServiceProvider;
4
use Closure;
5
use Illuminate\Contracts\Foundation\Application;
6
7
/**
8
 * Class     ValidatorServiceProvider
9
 *
10
 * @package  Arcanesoft\Auth\Providers
11
 * @author   ARCANEDEV <[email protected]>
12
 */
13
class ValidatorServiceProvider extends ServiceProvider
14
{
15
    /* -----------------------------------------------------------------
16
     |  Properties
17
     | -----------------------------------------------------------------
18
     */
19
    /**
20
     * The Validator instance.
21
     *
22
     * @var \Illuminate\Validation\Factory
23
     */
24
    protected $validator;
25
26
    /* -----------------------------------------------------------------
27
     |  Constructor
28
     | -----------------------------------------------------------------
29
     */
30
    /**
31
     * {@inheritdoc}
32
     */
33 12
    public function __construct(Application $app)
34
    {
35 12
        parent::__construct($app);
36
37 12
        $this->validator = $app['validator'];
38
    }
39
40
    /* ------------------------------------------------------------------------------------------------
41
     |  Main Functions
42
     | ------------------------------------------------------------------------------------------------
43
     */
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function boot()
48
    {
49
        $this->registerUserValidators();
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function register()
56
    {
57
        //
58
    }
59
60
    /* ------------------------------------------------------------------------------------------------
61
     |  Validators
62
     | ------------------------------------------------------------------------------------------------
63
     */
64
    /**
65
     * Register the user validators.
66
     */
67
    private function registerUserValidators()
68
    {
69
        $this->extendValidator(
70
            'user_password',
71
            \Arcanesoft\Auth\Validators\UserValidator::class,
72
            function($message, $attribute) {
73
                $message = 'auth::validation.user_password';
74
75
                return str_replace(':attribute', $attribute, trans($message));
76
            }
77
        );
78
    }
79
80
    /* ------------------------------------------------------------------------------------------------
81
     |  Other Functions
82
     | ------------------------------------------------------------------------------------------------
83
     */
84
    /**
85
     * Extend validator.
86
     *
87
     * @param  string         $name
88
     * @param  string         $class
89
     * @param  \Closure|null  $replacer
90
     */
91
    private function extendValidator($name, $class, Closure $replacer = null)
92
    {
93
        $this->validator->extend($name, "{$class}@validate" . studly_case($name));
94
95
        if ( ! is_null($replacer))
96
            $this->validator->replacer($name, $replacer);
97
    }
98
}
99