Completed
Pull Request — master (#21)
by ARCANEDEV
05:07
created

ValidatorServiceProvider   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 91.67%

Importance

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

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 12
    }
39
40
    /* ------------------------------------------------------------------------------------------------
41
     |  Main Functions
42
     | ------------------------------------------------------------------------------------------------
43
     */
44
    /**
45
     * {@inheritdoc}
46
     */
47 12
    public function boot()
48
    {
49 12
        $this->registerUserValidators();
50 12
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55 12
    public function register()
56
    {
57
        //
58 12
    }
59
60
    /* ------------------------------------------------------------------------------------------------
61
     |  Validators
62
     | ------------------------------------------------------------------------------------------------
63
     */
64
    /**
65
     * Register the user validators.
66
     */
67 12
    private function registerUserValidators()
68
    {
69 12
        $this->extendValidator(
70 12
            'user_password',
71 12
            \Arcanesoft\Auth\Validators\UserValidator::class,
72 6
            function($message, $attribute) {
73
                $message = 'auth::validation.user_password';
74
75
                return str_replace(':attribute', $attribute, trans($message));
76 6
            }
77 6
        );
78 12
    }
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 12
    private function extendValidator($name, $class, Closure $replacer = null)
92
    {
93 12
        $this->validator->extend($name, "{$class}@validate" . studly_case($name));
94
95 12
        if ( ! is_null($replacer))
96 12
            $this->validator->replacer($name, $replacer);
97 12
    }
98
}
99