Completed
Push — master ( d52c44...4a4a68 )
by Krishnaprasad
05:48
created

ClamavValidatorServiceProvider   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 90.32%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 0
loc 99
ccs 28
cts 31
cp 0.9032
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 17 1
A getRules() 0 4 1
A addNewRules() 0 6 2
A extendValidator() 0 7 2
A register() 0 3 1
A provides() 0 4 1
1
<?php namespace Sunspikes\ClamavValidator;
2
3
use Illuminate\Support\ServiceProvider;
4
5
class ClamavValidatorServiceProvider extends ServiceProvider
6
{
7
8
    /**
9
     * Indicates if loading of the provider is deferred.
10
     *
11
     * @var bool
12
     */
13
    protected $defer = false;
14
15
    /**
16
     * The list of validator rules.
17
     *
18
     * @var bool
19
     */
20
    protected $rules = [
21
        'clamav',
22
    ];
23
24
    /**
25
     * Bootstrap the application events.
26
     *
27
     * @return void
28
     */
29 1
    public function boot()
30
    {
31 1
        $this->loadTranslationsFrom(__DIR__ . '/../lang', 'clamav-validator');
32
33 1
        $this->app['validator']
34 1
            ->resolver(function ($translator, $data, $rules, $messages, $customAttributes = []) {
35 1
                return new ClamavValidator(
36 1
                    $translator,
37 1
                    $data,
38 1
                    $rules,
39 1
                    $messages,
40
                    $customAttributes
41 1
                );
42 1
            });
43
44 1
        $this->addNewRules();
45 1
    }
46
47
    /**
48
     * Get the list of new rules being added to the validator.
49
     *
50
     * @return array
51
     */
52 1
    public function getRules()
53
    {
54 1
        return $this->rules;
55
    }
56
57
58
    /**
59
     * Add new rules to the validator.
60
     */
61 1
    protected function addNewRules()
62
    {
63 1
        foreach ($this->getRules() as $rule) {
0 ignored issues
show
Bug introduced by
The expression $this->getRules() of type boolean is not traversable.
Loading history...
64 1
            $this->extendValidator($rule);
65 1
        }
66 1
    }
67
68
69
    /**
70
     * Extend the validator with new rules.
71
     *
72
     * @param  string $rule
73
     * @return void
74
     */
75 1
    protected function extendValidator($rule)
76
    {
77 1
        $method = studly_case($rule);
78 1
        $translation = $this->app['translator']->get('clamav-validator::validation');
79 1
        $this->app['validator']->extend($rule, ClamavValidator::class .'@validate' . $method,
80 1
            isset($translation[$rule]) ? $translation[$rule] : []);
81 1
    }
82
83
84
    /**
85
     * Register the service provider.
86
     *
87
     * @return void
88
     */
89
    public function register()
90
    {
91
    }
92
93
94
    /**
95
     * Get the services provided by the provider.
96
     *
97
     * @return array
98
     */
99 1
    public function provides()
100 1
    {
101
        return [];
102
    }
103
}
104