Passed
Push — master ( ac7ac5...67fb51 )
by Roberto
03:29
created

src/ReCaptchaServiceProvider.php (1 issue)

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->loadRoutesFrom(__DIR__ . '/routes/routes.php');
36
37
		$this->publishes([
38
			__DIR__ . '/../config/recaptcha.php' => config_path('recaptcha.php'),
39
		]);
40
41
	}
42
43
	/**
44
	 * Extends Validator to include a recaptcha type
45
	 */
46
	public function addValidationRule() {
47
48
		Validator::extendImplicit('recaptcha', function ($attribute, $value, $parameters, $validator) {
49
50
			return app('recaptcha')->validate($value);
1 ignored issue
show
The method validate() does not exist on Illuminate\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

50
			return app('recaptcha')->/** @scrutinizer ignore-call */ validate($value);

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...
51
		}, trans('validation.recaptcha'));
52
	}
53
54
	/**
55
	 * Register the service provider.
56
	 *
57
	 * @return void
58
	 */
59
	public function register() {
60
61
		$this->mergeConfigFrom(
62
			__DIR__ . '/../config/recaptcha.php', 'recaptcha'
63
		);
64
65
		$this->registerReCaptchaBuilder();
66
	}
67
68
	/**
69
	 * Register the HTML builder instance.
70
	 *
71
	 * @return void
72
	 */
73
	protected function registerReCaptchaBuilder() {
74
75
		$this->app->singleton('recaptcha', function ($app) {
76
77
			$recaptcha_class = '';
78
79
			switch (config('recaptcha.version')) {
80
				case 'v3' :
81
					$recaptcha_class = ReCaptchaBuilderV3::class;
82
					break;
83
				case 'v2' :
84
					$recaptcha_class = ReCaptchaBuilderV2::class;
85
					break;
86
				case 'invisible':
87
					$recaptcha_class = ReCaptchaBuilderInvisible::class;
88
					break;
89
			}
90
91
			return new $recaptcha_class(config('recaptcha.api_site_key'), config('recaptcha.api_secret_key'));
92
93
		});
94
	}
95
96
	/**
97
	 * Get the services provided by the provider.
98
	 *
99
	 * @return array
100
	 */
101
	public function provides() {
102
103
		return ['recaptcha'];
104
	}
105
106
}
107