Completed
Push — master ( 835da2...f8eb08 )
by Krishnaprasad
05:09
created

ClamavValidatorServiceProvider   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 93.1%

Importance

Changes 0
Metric Value
wmc 8
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 98
ccs 27
cts 29
cp 0.931
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 16 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) {
35 1
                return new ClamavValidator(
36 1
                    $translator,
37 1
                    $data,
38 1
                    $rules,
39
                    $messages
40 1
                );
41 1
            });
42
43 1
        $this->addNewRules();
44 1
    }
45
46
    /**
47
     * Get the list of new rules being added to the validator.
48
     *
49
     * @return array
50
     */
51 1
    public function getRules()
52
    {
53 1
        return $this->rules;
54
    }
55
56
57
    /**
58
     * Add new rules to the validator.
59
     */
60 1
    protected function addNewRules()
61
    {
62 1
        foreach ($this->getRules() as $rule) {
0 ignored issues
show
Bug introduced by Krishnaprasad MG
The expression $this->getRules() of type boolean is not traversable.
Loading history...
63 1
            $this->extendValidator($rule);
64 1
        }
65 1
    }
66
67
68
    /**
69
     * Extend the validator with new rules.
70
     *
71
     * @param  string $rule
72
     * @return void
73
     */
74 1
    protected function extendValidator($rule)
75
    {
76 1
        $method = studly_case($rule);
77 1
        $translation = $this->app['translator']->get('clamav-validator::validation');
78 1
        $this->app['validator']->extend($rule, ClamavValidator::class .'@validate' . $method,
79 1
            isset($translation[$rule]) ? $translation[$rule] : []);
80 1
    }
81
82
83
    /**
84
     * Register the service provider.
85
     *
86
     * @return void
87
     */
88
    public function register()
89
    {
90
    }
91
92
93
    /**
94
     * Get the services provided by the provider.
95
     *
96
     * @return array
97
     */
98 1
    public function provides()
99
    {
100 1
        return [];
101
    }
102
}
103