Passed
Push — master ( f4ebdd...dfd859 )
by Roberto
03:09
created

src/ReCaptchaServiceProvider.php (3 issues)

Labels
Severity
1
<?php
2
/**
3
 * Copyright (c) 2017 - present
4
 * LaravelGoogleRecaptcha - ReCaptchaServiceProvider.php
5
 * author: Roberto Belotti - [email protected]
6
 * web : robertobelotti.com, github.com/biscolab
7
 * Initial version created on: 12/9/2018
8
 * MIT license: https://github.com/biscolab/laravel-recaptcha/blob/master/LICENSE
9
 */
10
11
namespace Biscolab\ReCaptcha;
12
13
use Illuminate\Support\ServiceProvider;
14
use Validator;
15
16
/**
17
 * Class ReCaptchaServiceProvider
18
 * @package Biscolab\ReCaptcha
19
 */
20
class ReCaptchaServiceProvider extends ServiceProvider {
21
22
    /**
23
     * Indicates if loading of the provider is deferred.
24
     *
25
     * @var bool
26
     */
27
    protected $defer = false;
28
29
    /**
30
     *
31
     */
32
    public function boot() {
33
34
        $this->addValidationRule();
35
        $this->publishes([
0 ignored issues
show
The method publishes() does not exist on Biscolab\ReCaptcha\ReCaptchaServiceProvider. ( Ignorable by Annotation )

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

35
        $this->/** @scrutinizer ignore-call */ 
36
               publishes([

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...
36
            __DIR__ . '/../config/recaptcha.php' => config_path('recaptcha.php'),
37
        ]);
38
    }
39
40
    /**
41
     * Extends Validator to include a recaptcha type
42
     */
43
    public function addValidationRule() {
44
45
        Validator::extendImplicit('recaptcha', function ($attribute, $value, $parameters, $validator) {
46
47
            return app('recaptcha')->validate($value);
48
        }, trans('validation.recaptcha'));
49
    }
50
51
    /**
52
     * Register the service provider.
53
     *
54
     * @return void
55
     */
56
    public function register() {
57
58
        $this->mergeConfigFrom(
0 ignored issues
show
The method mergeConfigFrom() does not exist on Biscolab\ReCaptcha\ReCaptchaServiceProvider. ( Ignorable by Annotation )

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

58
        $this->/** @scrutinizer ignore-call */ 
59
               mergeConfigFrom(

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...
59
            __DIR__ . '/../config/recaptcha.php', 'recaptcha'
60
        );
61
62
        $this->registerReCaptchaBuilder();
63
    }
64
65
    /**
66
     * Register the HTML builder instance.
67
     *
68
     * @return void
69
     */
70
    protected function registerReCaptchaBuilder() {
71
72
        $this->app->singleton('recaptcha', function ($app) {
0 ignored issues
show
The method singleton() does not exist on App. ( Ignorable by Annotation )

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

72
        $this->app->/** @scrutinizer ignore-call */ 
73
                    singleton('recaptcha', function ($app) {

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...
73
74
            if (config('recaptcha.version') == 'v2') {
75
                return new ReCaptchaBuilderV2(config('recaptcha.api_site_key'), config('recaptcha.api_secret_key'), config('recaptcha.version'));
76
            } else {
77
                return new ReCaptchaBuilderInvisible(config('recaptcha.api_site_key'), config('recaptcha.api_secret_key'), config('recaptcha.version'));
78
            }
79
        });
80
    }
81
82
    /**
83
     * Get the services provided by the provider.
84
     *
85
     * @return array
86
     */
87
    public function provides() {
88
89
        return ['recaptcha'];
90
    }
91
92
}
93