Completed
Pull Request — master (#132)
by
unknown
02:04
created

CaptchaServiceProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 59
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
B boot() 0 24 3
A register() 0 20 1
1
<?php
2
3
namespace Heimuya\Captcha;
4
5
use Illuminate\Support\ServiceProvider;
6
7
/**
8
 * Class CaptchaServiceProvider
9
 * @package Heimuya\Captcha
10
 */
11
class CaptchaServiceProvider extends ServiceProvider {
12
13
    /**
14
     * Boot the service provider.
15
     *
16
     * @return null
17
     */
18
    public function boot()
19
    {
20
        // Publish configuration files
21
        $this->publishes([
22
            __DIR__.'/../config/captcha.php' => config_path('captcha.php')
23
        ], 'config');
24
25
        // HTTP routing
26
        if (strpos($this->app->version(), 'Lumen') !== false) {
27
           $this->app->get('captcha[/{config}]', 'Heimuya\Captcha\LumenCaptchaController@getCaptcha');
0 ignored issues
show
Unused Code introduced by
The call to Application::get() has too many arguments starting with 'Heimuya\\Captcha\\Lumen...aController@getCaptcha'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
28
        } else {
29
            if ((double) $this->app->version() >= 5.2) {
30
                $this->app['router']->get('captcha/{config?}', '\Heimuya\Captcha\CaptchaController@getCaptcha')->middleware('web');
31
            } else {
32
                $this->app['router']->get('captcha/{config?}', '\Heimuya\Captcha\CaptchaController@getCaptcha');
33
            }
34
        }
35
36
        // Validator extensions
37
        $this->app['validator']->extend('captcha', function($attribute, $value, $parameters)
0 ignored issues
show
Unused Code introduced by
The parameter $parameters is not used and could be removed.

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

Loading history...
38
        {
39
            return captcha_check($value);
40
        });
41
    }
42
43
    /**
44
     * Register the service provider.
45
     *
46
     * @return void
47
     */
48
    public function register()
49
    {
50
        // Merge configs
51
        $this->mergeConfigFrom(
52
            __DIR__.'/../config/captcha.php', 'captcha'
53
        );
54
55
        // Bind captcha
56
        $this->app->bind('captcha', function($app)
57
        {
58
            return new Captcha(
59
                $app['Illuminate\Filesystem\Filesystem'],
60
                $app['Illuminate\Config\Repository'],
61
                $app['Intervention\Image\ImageManager'],
62
                $app['Illuminate\Session\Store'],
63
                $app['Illuminate\Hashing\BcryptHasher'],
64
                $app['Illuminate\Support\Str']
65
            );
66
        });
67
    }
68
69
}
70