Completed
Push — master ( 542729...ce6d01 )
by Krishnaprasad
04:21
created

ClamavValidator/ClamavValidatorServiceProvider.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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 = array(
21
        'clamav',
22
    );
23
24
    /**
25
     * Bootstrap the application events.
26
     *
27
     * @return void
28
     */
29 1
    public function boot()
30
    {
31 1
        $this->package('sunspikes/clamav-validator', 'clamav-validator');
0 ignored issues
show
Documentation Bug introduced by
The method package does not exist on object<Sunspikes\ClamavV...lidatorServiceProvider>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
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) {
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, 'Sunspikes\ClamavValidator\ClamavValidator@validate' . $method,
79 1
            isset($translation[$rule]) ? $translation[$rule] : array());
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
    public function provides()
99
    {
100
        return array();
101
    }
102
}
103