CaptchaServiceProvider   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 20
dl 0
loc 91
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A publish() 0 5 1
A boot() 0 18 1
A bindRouteFile() 0 5 1
A bindViewFile() 0 5 1
A register() 0 8 1
A prepare() 0 3 1
1
<?php
2
3
namespace Shetabit\Captcha\Provider;
4
5
use Shetabit\Captcha\CaptchaManager;
6
use Illuminate\Support\ServiceProvider;
7
8
class CaptchaServiceProvider extends ServiceProvider
9
{
10
    /**
11
     * Perform post-registration booting of services.
12
     *
13
     * @return void
14
     */
15
    public function boot()
16
    {
17
        /**
18
         * Configurations that needs to be done by user.
19
         */
20
        $this->publish(
21
            __DIR__ . '/../../config/captcha.php',
22
            config_path('captcha.php'),
23
            'config'
24
        );
25
26
        // Validator extensions
27
        $this->app['validator']->extend(
28
            config('captcha.validator','captcha'),
29
            function($attribute, $value, $parameters) {
0 ignored issues
show
Unused Code introduced by
The parameter $parameters is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

29
            function($attribute, $value, /** @scrutinizer ignore-unused */ $parameters) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
30
                return captcha_verify($value);
31
            },
32
            'Inserted :attribute is not valid.'
33
        );
34
    }
35
36
    /**
37
     * Register any package services.
38
     *
39
     * @return void
40
     */
41
    public function register()
42
    {
43
        // Bind captcha manager
44
        $this->app->bind('shetabit-captcha', function () {
45
            return new CaptchaManager($this, config('captcha'));
46
        });
47
48
        $this->prepare();
49
    }
50
51
    /**
52
     *  Prepare requirements
53
     */
54
    private function prepare()
55
    {
56
        app('shetabit-captcha')->prepareDriver();
0 ignored issues
show
Bug introduced by
The method prepareDriver() does not exist on Illuminate\Contracts\Foundation\Application. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

56
        app('shetabit-captcha')->/** @scrutinizer ignore-call */ prepareDriver();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
57
    }
58
59
    /**
60
     * View binder
61
     *
62
     * @param $from
63
     * @param $namespace
64
     * @return $this
65
     */
66
    public function bindViewFile($from, $namespace)
67
    {
68
        $this->loadViewsFrom($from, $namespace);
69
70
        return $this;
71
    }
72
73
    /**
74
     * Route binder
75
     *
76
     * @param $route
77
     * @return $this
78
     */
79
    public function bindRouteFile($route)
80
    {
81
        $this->loadRoutesFrom($route);
82
83
        return $this;
84
    }
85
86
    /**
87
     * Publisher
88
     *
89
     * @param $from
90
     * @param $to
91
     * @param null $group
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $group is correct as it would always require null to be passed?
Loading history...
92
     * @return $this
93
     */
94
    public function publish($from, $to, $group = null)
95
    {
96
        $this->publishes([$from => $to], $group);
97
98
        return $this;
99
    }
100
}
101