Completed
Push — master ( f40498...e3ae3a )
by ARCANEDEV
03:17
created

ValidatorServiceProvider   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 90.91%

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 20
cts 22
cp 0.9091
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A boot() 0 4 1
A register() 0 4 1
A registerUserValidators() 0 10 1
A extendValidator() 0 8 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 24
    public function __construct(Application $app)
34
    {
35 24
        parent::__construct($app);
36
37
        /** @var  \    $validator */
38 24
        $this->validator = $app['validator'];
39 24
    }
40
41
    /* ------------------------------------------------------------------------------------------------
42
     |  Main Functions
43
     | ------------------------------------------------------------------------------------------------
44
     */
45
    /**
46
     * {@inheritdoc}
47
     */
48 24
    public function boot()
49
    {
50 24
        $this->registerUserValidators();
51 24
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56 24
    public function register()
57
    {
58
        //
59 24
    }
60
61
    /* ------------------------------------------------------------------------------------------------
62
     |  Validators
63
     | ------------------------------------------------------------------------------------------------
64
     */
65
    /**
66
     * Register the user validators.
67
     */
68 24
    private function registerUserValidators()
69
    {
70 24
        $class = \Arcanesoft\Auth\Validators\UserValidator::class;
71
72 24
        $this->extendValidator('user_password', $class, function($message, $attribute) {
73
            $message = 'auth::validation.user_password';
74
75
            return str_replace(':attribute', $attribute, trans($message));
76 24
        });
77 24
    }
78
79
    /* ------------------------------------------------------------------------------------------------
80
     |  Other Functions
81
     | ------------------------------------------------------------------------------------------------
82
     */
83
    /**
84
     * Extend validator.
85
     *
86
     * @param  string         $name
87
     * @param  string         $class
88
     * @param  \Closure|null  $replacer
89
     */
90 24
    private function extendValidator($name, $class, Closure $replacer = null)
91
    {
92 24
        $this->validator->extend($name, $class . '@validate' . studly_case($name));
93
94 24
        if ( ! is_null($replacer)) {
95 24
            $this->validator->replacer($name, $replacer);
96 18
        }
97 24
    }
98
}
99