Passed
Branch master (7b9b82)
by Roberto
15:23
created
src/ReCaptchaServiceProvider.php 1 patch
Indentation   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -20,103 +20,103 @@
 block discarded – undo
20 20
  */
21 21
 class ReCaptchaServiceProvider extends ServiceProvider {
22 22
 
23
-	/**
24
-	 * Indicates if loading of the provider is deferred.
25
-	 *
26
-	 * @var bool
27
-	 */
28
-	protected $defer = false;
29
-
30
-	/**
31
-	 *
32
-	 */
33
-	public function boot() {
34
-
35
-		$this->addValidationRule();
23
+    /**
24
+     * Indicates if loading of the provider is deferred.
25
+     *
26
+     * @var bool
27
+     */
28
+    protected $defer = false;
29
+
30
+    /**
31
+     *
32
+     */
33
+    public function boot() {
34
+
35
+        $this->addValidationRule();
36 36
 //		$this->loadRoutesFrom(__DIR__ . '/routes/routes.php');
37
-		$this->registerRoutes();
38
-		$this->publishes([
39
-			__DIR__ . '/../config/recaptcha.php' => config_path('recaptcha.php'),
40
-		]);
41
-
42
-	}
43
-
44
-	/**
45
-	 * Extends Validator to include a recaptcha type
46
-	 */
47
-	public function addValidationRule() {
48
-
49
-		Validator::extendImplicit('recaptcha', function ($attribute, $value, $parameters, $validator) {
50
-
51
-			return app('recaptcha')->validate($value);
52
-		}, trans('validation.recaptcha'));
53
-	}
54
-
55
-	/**
56
-	 * Register the service provider.
57
-	 *
58
-	 * @return void
59
-	 */
60
-	public function register() {
61
-
62
-		$this->mergeConfigFrom(
63
-			__DIR__ . '/../config/recaptcha.php', 'recaptcha'
64
-		);
65
-
66
-		$this->registerReCaptchaBuilder();
67
-	}
68
-
69
-	/**
70
-	 * Get the services provided by the provider.
71
-	 *
72
-	 * @return array
73
-	 */
74
-	public function provides(): array {
75
-
76
-		return ['recaptcha'];
77
-	}
78
-
79
-	/**
80
-	 * @return ReCaptchaServiceProvider
81
-	 *
82
-	 * @since v3.4.1
83
-	 */
84
-	protected function registerRoutes(): ReCaptchaServiceProvider {
85
-
86
-		Route::get(
87
-			config('recaptcha.default_validation_route', 'biscolab-recaptcha/validate'),
88
-			['uses' => 'Biscolab\ReCaptcha\Controllers\ReCaptchaController@validateV3']
89
-		)->middleware('web');
90
-
91
-		return $this;
92
-	}
93
-
94
-	/**
95
-	 * Register the HTML builder instance.
96
-	 *
97
-	 * @return void
98
-	 */
99
-	protected function registerReCaptchaBuilder() {
100
-
101
-		$this->app->singleton('recaptcha', function ($app) {
102
-
103
-			$recaptcha_class = '';
104
-
105
-			switch (config('recaptcha.version')) {
106
-				case 'v3' :
107
-					$recaptcha_class = ReCaptchaBuilderV3::class;
108
-					break;
109
-				case 'v2' :
110
-					$recaptcha_class = ReCaptchaBuilderV2::class;
111
-					break;
112
-				case 'invisible':
113
-					$recaptcha_class = ReCaptchaBuilderInvisible::class;
114
-					break;
115
-			}
116
-
117
-			return new $recaptcha_class(config('recaptcha.api_site_key'), config('recaptcha.api_secret_key'), config('recaptcha.curl_timeout'));
118
-
119
-		});
120
-	}
37
+        $this->registerRoutes();
38
+        $this->publishes([
39
+            __DIR__ . '/../config/recaptcha.php' => config_path('recaptcha.php'),
40
+        ]);
41
+
42
+    }
43
+
44
+    /**
45
+     * Extends Validator to include a recaptcha type
46
+     */
47
+    public function addValidationRule() {
48
+
49
+        Validator::extendImplicit('recaptcha', function ($attribute, $value, $parameters, $validator) {
50
+
51
+            return app('recaptcha')->validate($value);
52
+        }, trans('validation.recaptcha'));
53
+    }
54
+
55
+    /**
56
+     * Register the service provider.
57
+     *
58
+     * @return void
59
+     */
60
+    public function register() {
61
+
62
+        $this->mergeConfigFrom(
63
+            __DIR__ . '/../config/recaptcha.php', 'recaptcha'
64
+        );
65
+
66
+        $this->registerReCaptchaBuilder();
67
+    }
68
+
69
+    /**
70
+     * Get the services provided by the provider.
71
+     *
72
+     * @return array
73
+     */
74
+    public function provides(): array {
75
+
76
+        return ['recaptcha'];
77
+    }
78
+
79
+    /**
80
+     * @return ReCaptchaServiceProvider
81
+     *
82
+     * @since v3.4.1
83
+     */
84
+    protected function registerRoutes(): ReCaptchaServiceProvider {
85
+
86
+        Route::get(
87
+            config('recaptcha.default_validation_route', 'biscolab-recaptcha/validate'),
88
+            ['uses' => 'Biscolab\ReCaptcha\Controllers\ReCaptchaController@validateV3']
89
+        )->middleware('web');
90
+
91
+        return $this;
92
+    }
93
+
94
+    /**
95
+     * Register the HTML builder instance.
96
+     *
97
+     * @return void
98
+     */
99
+    protected function registerReCaptchaBuilder() {
100
+
101
+        $this->app->singleton('recaptcha', function ($app) {
102
+
103
+            $recaptcha_class = '';
104
+
105
+            switch (config('recaptcha.version')) {
106
+                case 'v3' :
107
+                    $recaptcha_class = ReCaptchaBuilderV3::class;
108
+                    break;
109
+                case 'v2' :
110
+                    $recaptcha_class = ReCaptchaBuilderV2::class;
111
+                    break;
112
+                case 'invisible':
113
+                    $recaptcha_class = ReCaptchaBuilderInvisible::class;
114
+                    break;
115
+            }
116
+
117
+            return new $recaptcha_class(config('recaptcha.api_site_key'), config('recaptcha.api_secret_key'), config('recaptcha.curl_timeout'));
118
+
119
+        });
120
+    }
121 121
 
122 122
 }
Please login to merge, or discard this patch.
config/recaptcha.php 1 patch
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -13,60 +13,60 @@
 block discarded – undo
13 13
  */
14 14
 return [
15 15
 
16
-	/**
17
-	 *
18
-	 * The site key
19
-	 * get site key @ www.google.com/recaptcha/admin
20
-	 *
21
-	 */
22
-	'api_site_key'                 => env('RECAPTCHA_SITE_KEY', ''),
16
+    /**
17
+     *
18
+     * The site key
19
+     * get site key @ www.google.com/recaptcha/admin
20
+     *
21
+     */
22
+    'api_site_key'                 => env('RECAPTCHA_SITE_KEY', ''),
23 23
 
24
-	/**
25
-	 *
26
-	 * The secret key
27
-	 * get secret key @ www.google.com/recaptcha/admin
28
-	 *
29
-	 */
30
-	'api_secret_key'               => env('RECAPTCHA_SECRET_KEY', ''),
24
+    /**
25
+     *
26
+     * The secret key
27
+     * get secret key @ www.google.com/recaptcha/admin
28
+     *
29
+     */
30
+    'api_secret_key'               => env('RECAPTCHA_SECRET_KEY', ''),
31 31
 
32
-	/**
33
-	 *
34
-	 * ReCATCHA version
35
-	 * Supported: "v2", "invisible", "v3",
36
-	 *
37
-	 * get more info @ https://developers.google.com/recaptcha/docs/versions
38
-	 *
39
-	 */
40
-	'version'                      => env('RECAPTCHA_DEFAULT_VERSION', 'v2'),
32
+    /**
33
+     *
34
+     * ReCATCHA version
35
+     * Supported: "v2", "invisible", "v3",
36
+     *
37
+     * get more info @ https://developers.google.com/recaptcha/docs/versions
38
+     *
39
+     */
40
+    'version'                      => env('RECAPTCHA_DEFAULT_VERSION', 'v2'),
41 41
 
42
-	/**
43
-	 *
44
-	 * The curl timout in seconds to validate a recaptcha token
45
-	 * @since v3.5.0
46
-	 *
47
-	 */
48
-	'curl_timeout'                 => env('RECAPTCHA_CURL_TIMEOUT', 10),
42
+    /**
43
+     *
44
+     * The curl timout in seconds to validate a recaptcha token
45
+     * @since v3.5.0
46
+     *
47
+     */
48
+    'curl_timeout'                 => env('RECAPTCHA_CURL_TIMEOUT', 10),
49 49
 
50
-	/**
51
-	 *
52
-	 * IP addresses for which validation will be skipped
53
-	 *
54
-	 */
55
-	'skip_ip'                      => [],
50
+    /**
51
+     *
52
+     * IP addresses for which validation will be skipped
53
+     *
54
+     */
55
+    'skip_ip'                      => [],
56 56
 
57
-	/**
58
-	 *
59
-	 * Default route called to check the Google reCAPTCHA token
60
-	 * @since v3.2.0
61
-	 *
62
-	 */
63
-	'default_validation_route'     => env('RECAPTCHA_DEFAULT_VALIDATION_ROUTE', 'biscolab-recaptcha/validate'),
57
+    /**
58
+     *
59
+     * Default route called to check the Google reCAPTCHA token
60
+     * @since v3.2.0
61
+     *
62
+     */
63
+    'default_validation_route'     => env('RECAPTCHA_DEFAULT_VALIDATION_ROUTE', 'biscolab-recaptcha/validate'),
64 64
 
65
-	/**
66
-	 *
67
-	 * The name of the parameter used to send Google reCAPTCHA token to verify route
68
-	 * @since v3.2.0
69
-	 *
70
-	 */
71
-	'default_token_parameter_name' => env('RECAPTCHA_DEFAULT_TOKEN_PARAMETER_NAME', 'token')
65
+    /**
66
+     *
67
+     * The name of the parameter used to send Google reCAPTCHA token to verify route
68
+     * @since v3.2.0
69
+     *
70
+     */
71
+    'default_token_parameter_name' => env('RECAPTCHA_DEFAULT_TOKEN_PARAMETER_NAME', 'token')
72 72
 ];
Please login to merge, or discard this patch.
src/ReCaptchaBuilderInvisible.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -16,29 +16,29 @@
 block discarded – undo
16 16
  */
17 17
 class ReCaptchaBuilderInvisible extends ReCaptchaBuilder {
18 18
 
19
-	/**
20
-	 * ReCaptchaBuilderInvisible constructor.
21
-	 *
22
-	 * @param string   $api_site_key
23
-	 * @param string   $api_secret_key
24
-	 * @param int|null $curl_timeout
25
-	 */
26
-	public function __construct(string $api_site_key, string $api_secret_key, ?int $curl_timeout = null) {
19
+    /**
20
+     * ReCaptchaBuilderInvisible constructor.
21
+     *
22
+     * @param string   $api_site_key
23
+     * @param string   $api_secret_key
24
+     * @param int|null $curl_timeout
25
+     */
26
+    public function __construct(string $api_site_key, string $api_secret_key, ?int $curl_timeout = null) {
27 27
 
28
-		parent::__construct($api_site_key, $api_secret_key, 'invisible', $curl_timeout);
29
-	}
28
+        parent::__construct($api_site_key, $api_secret_key, 'invisible', $curl_timeout);
29
+    }
30 30
 
31
-	/**
32
-	 * Write HTML <button> tag in your HTML code
33
-	 * Insert before </form> tag
34
-	 *
35
-	 * @param string $buttonInnerHTML
36
-	 *
37
-	 * @return string
38
-	 */
39
-	public function htmlFormButton($buttonInnerHTML = 'Submit'): string {
31
+    /**
32
+     * Write HTML <button> tag in your HTML code
33
+     * Insert before </form> tag
34
+     *
35
+     * @param string $buttonInnerHTML
36
+     *
37
+     * @return string
38
+     */
39
+    public function htmlFormButton($buttonInnerHTML = 'Submit'): string {
40 40
 
41
-		return ($this->version == 'invisible') ? '<button class="g-recaptcha" data-sitekey="' . $this->api_site_key . '" data-callback="biscolabLaravelReCaptcha">' . $buttonInnerHTML . '</button>' : '';
42
-	}
41
+        return ($this->version == 'invisible') ? '<button class="g-recaptcha" data-sitekey="' . $this->api_site_key . '" data-callback="biscolabLaravelReCaptcha">' . $buttonInnerHTML . '</button>' : '';
42
+    }
43 43
 
44 44
 }
45 45
\ No newline at end of file
Please login to merge, or discard this patch.
src/ReCaptchaBuilderV2.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -16,26 +16,26 @@
 block discarded – undo
16 16
  */
17 17
 class ReCaptchaBuilderV2 extends ReCaptchaBuilder {
18 18
 
19
-	/**
20
-	 * ReCaptchaBuilderV2 constructor.
21
-	 *
22
-	 * @param string   $api_site_key
23
-	 * @param string   $api_secret_key
24
-	 * @param int|null $curl_timeout
25
-	 */
26
-	public function __construct(string $api_site_key, string $api_secret_key, ?int $curl_timeout = null) {
19
+    /**
20
+     * ReCaptchaBuilderV2 constructor.
21
+     *
22
+     * @param string   $api_site_key
23
+     * @param string   $api_secret_key
24
+     * @param int|null $curl_timeout
25
+     */
26
+    public function __construct(string $api_site_key, string $api_secret_key, ?int $curl_timeout = null) {
27 27
 
28
-		parent::__construct($api_site_key, $api_secret_key, 'v2', $curl_timeout);
29
-	}
28
+        parent::__construct($api_site_key, $api_secret_key, 'v2', $curl_timeout);
29
+    }
30 30
 
31
-	/**
32
-	 * Write ReCAPTCHA HTML tag in your FORM
33
-	 * Insert before </form> tag
34
-	 * @return string
35
-	 */
36
-	public function htmlFormSnippet(): string {
31
+    /**
32
+     * Write ReCAPTCHA HTML tag in your FORM
33
+     * Insert before </form> tag
34
+     * @return string
35
+     */
36
+    public function htmlFormSnippet(): string {
37 37
 
38
-		return ($this->version == 'v2') ? '<div class="g-recaptcha" data-sitekey="' . $this->api_site_key . '"></div>' : '';
39
-	}
38
+        return ($this->version == 'v2') ? '<div class="g-recaptcha" data-sitekey="' . $this->api_site_key . '"></div>' : '';
39
+    }
40 40
 
41 41
 }
42 42
\ No newline at end of file
Please login to merge, or discard this patch.
src/ReCaptchaBuilderV3.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -16,16 +16,16 @@
 block discarded – undo
16 16
  */
17 17
 class ReCaptchaBuilderV3 extends ReCaptchaBuilder {
18 18
 
19
-	/**
20
-	 * ReCaptchaBuilderV3 constructor.
21
-	 *
22
-	 * @param string   $api_site_key
23
-	 * @param string   $api_secret_key
24
-	 * @param int|null $curl_timeout
25
-	 */
26
-	public function __construct(string $api_site_key, string $api_secret_key, ?int $curl_timeout = null) {
19
+    /**
20
+     * ReCaptchaBuilderV3 constructor.
21
+     *
22
+     * @param string   $api_site_key
23
+     * @param string   $api_secret_key
24
+     * @param int|null $curl_timeout
25
+     */
26
+    public function __construct(string $api_site_key, string $api_secret_key, ?int $curl_timeout = null) {
27 27
 
28
-		parent::__construct($api_site_key, $api_secret_key, 'v3', $curl_timeout);
29
-	}
28
+        parent::__construct($api_site_key, $api_secret_key, 'v3', $curl_timeout);
29
+    }
30 30
 
31 31
 }
32 32
\ No newline at end of file
Please login to merge, or discard this patch.
src/ReCaptchaBuilder.php 3 patches
Indentation   +307 added lines, -307 removed lines patch added patch discarded remove patch
@@ -19,237 +19,237 @@  discard block
 block discarded – undo
19 19
  */
20 20
 class ReCaptchaBuilder {
21 21
 
22
-	/**
23
-	 * @var string
24
-	 */
25
-	const DEFAULT_API_VERSION = 'v2';
26
-
27
-	/**
28
-	 * @var int
29
-	 */
30
-	const DEFAULT_CURL_TIMEOUT = 10;
31
-
32
-	/**
33
-	 * The Site key
34
-	 * please visit https://developers.google.com/recaptcha/docs/start
35
-	 * @var string
36
-	 */
37
-	protected $api_site_key;
38
-
39
-	/**
40
-	 * The Secret key
41
-	 * please visit https://developers.google.com/recaptcha/docs/start
42
-	 * @var string
43
-	 */
44
-	protected $api_secret_key;
45
-
46
-	/**
47
-	 * The chosen ReCAPTCHA version
48
-	 * please visit https://developers.google.com/recaptcha/docs/start
49
-	 * @var string
50
-	 */
51
-	protected $version;
52
-
53
-	/**
54
-	 * The curl timeout
55
-	 * please visit https://curl.haxx.se/libcurl/c/CURLOPT_TIMEOUT.html
56
-	 * @var int
57
-	 */
58
-	protected $curl_timeout;
59
-
60
-	/**
61
-	 * Whether is true the ReCAPTCHA is inactive
62
-	 * @var boolean
63
-	 */
64
-	protected $skip_by_ip = false;
65
-
66
-	/**
67
-	 * The API request URI
68
-	 */
69
-	protected $api_url = 'https://www.google.com/recaptcha/api/siteverify';
70
-
71
-	/**
72
-	 * ReCaptchaBuilder constructor.
73
-	 *
74
-	 * @param string      $api_site_key
75
-	 * @param string      $api_secret_key
76
-	 * @param null|string $version
77
-	 * @param int|null    $curl_timeout
78
-	 */
79
-	public function __construct(
80
-		string $api_site_key,
81
-		string $api_secret_key,
82
-		?string $version = self::DEFAULT_API_VERSION,
83
-		?int $curl_timeout = self::DEFAULT_CURL_TIMEOUT
84
-	) {
85
-
86
-		$this->setApiSiteKey($api_site_key);
87
-		$this->setApiSecretKey($api_secret_key);
88
-		$this->setVersion($version);
89
-		$this->setCurlTimeout($curl_timeout);
90
-		$this->setSkipByIp($this->skipByIp());
91
-	}
92
-
93
-	/**
94
-	 * @param string $api_site_key
95
-	 *
96
-	 * @return ReCaptchaBuilder
97
-	 */
98
-	public function setApiSiteKey(string $api_site_key): ReCaptchaBuilder {
99
-
100
-		$this->api_site_key = $api_site_key;
101
-
102
-		return $this;
103
-	}
104
-
105
-	/**
106
-	 * @param string $api_secret_key
107
-	 *
108
-	 * @return ReCaptchaBuilder
109
-	 */
110
-	public function setApiSecretKey(string $api_secret_key): ReCaptchaBuilder {
111
-
112
-		$this->api_secret_key = $api_secret_key;
113
-
114
-		return $this;
115
-	}
116
-
117
-	/**
118
-	 * @param int|null $curl_timeout
119
-	 *
120
-	 * @return ReCaptchaBuilder
121
-	 */
122
-	public function setCurlTimeout(?int $curl_timeout = null): ReCaptchaBuilder {
123
-
124
-		if($curl_timeout === null) {
125
-			$curl_timeout = config('recaptcha.curl_timeout', ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT);
126
-		}
127
-		$this->curl_timeout = $curl_timeout;
128
-
129
-		return $this;
130
-	}
131
-
132
-	/**
133
-	 * @return int
134
-	 */
135
-	public function getCurlTimeout(): int {
136
-
137
-		return $this->curl_timeout;
138
-	}
139
-
140
-	/**
141
-	 * @param string $version
142
-	 *
143
-	 * @return ReCaptchaBuilder
144
-	 */
145
-	public function setVersion(string $version): ReCaptchaBuilder {
146
-
147
-		$this->version = $version;
148
-
149
-		return $this;
150
-	}
151
-
152
-	/**
153
-	 * @return string
154
-	 */
155
-	public function getVersion(): string {
156
-
157
-		return $this->version;
158
-	}
159
-
160
-	/**
161
-	 * @param bool $skip_by_ip
162
-	 *
163
-	 * @return ReCaptchaBuilder
164
-	 */
165
-	public function setSkipByIp(bool $skip_by_ip): ReCaptchaBuilder {
166
-
167
-		$this->skip_by_ip = $skip_by_ip;
168
-
169
-		return $this;
170
-	}
171
-
172
-	/**
173
-	 * @return array|mixed
174
-	 */
175
-	public function getIpWhitelist() {
176
-
177
-		$whitelist = config('recaptcha.skip_ip', []);
178
-
179
-		if (!is_array($whitelist)) {
180
-			$whitelist = explode(',', $whitelist);
181
-		}
182
-
183
-		return $whitelist;
184
-	}
185
-
186
-	/**
187
-	 * Checks whether the user IP address is among IPs "to be skipped"
188
-	 *
189
-	 * @return boolean
190
-	 */
191
-	public function skipByIp(): bool {
192
-
193
-		return (in_array(request()->ip(), $this->getIpWhitelist()));
194
-	}
195
-
196
-	/**
197
-	 * Write script HTML tag in you HTML code
198
-	 * Insert before </head> tag
199
-	 *
200
-	 * @param string|null $formId
201
-	 * @param array|null  $configuration
202
-	 *
203
-	 * @return string
204
-	 * @throws Exception
205
-	 */
206
-	public function htmlScriptTagJsApi(?string $formId = '', ?array $configuration = []): string {
207
-
208
-		if ($this->skip_by_ip) {
209
-			return '';
210
-		}
211
-
212
-		switch ($this->version) {
213
-			case 'v3':
214
-				$html = "<script src=\"https://www.google.com/recaptcha/api.js?render={$this->api_site_key}\"></script>";
215
-				break;
216
-			default:
217
-				$html = "<script src=\"https://www.google.com/recaptcha/api.js\" async defer></script>";
218
-		}
219
-
220
-		if ($this->version == 'invisible') {
221
-			if (!$formId) {
222
-				throw new Exception("formId required", 1);
223
-			}
224
-			$html .= '<script>
22
+    /**
23
+     * @var string
24
+     */
25
+    const DEFAULT_API_VERSION = 'v2';
26
+
27
+    /**
28
+     * @var int
29
+     */
30
+    const DEFAULT_CURL_TIMEOUT = 10;
31
+
32
+    /**
33
+     * The Site key
34
+     * please visit https://developers.google.com/recaptcha/docs/start
35
+     * @var string
36
+     */
37
+    protected $api_site_key;
38
+
39
+    /**
40
+     * The Secret key
41
+     * please visit https://developers.google.com/recaptcha/docs/start
42
+     * @var string
43
+     */
44
+    protected $api_secret_key;
45
+
46
+    /**
47
+     * The chosen ReCAPTCHA version
48
+     * please visit https://developers.google.com/recaptcha/docs/start
49
+     * @var string
50
+     */
51
+    protected $version;
52
+
53
+    /**
54
+     * The curl timeout
55
+     * please visit https://curl.haxx.se/libcurl/c/CURLOPT_TIMEOUT.html
56
+     * @var int
57
+     */
58
+    protected $curl_timeout;
59
+
60
+    /**
61
+     * Whether is true the ReCAPTCHA is inactive
62
+     * @var boolean
63
+     */
64
+    protected $skip_by_ip = false;
65
+
66
+    /**
67
+     * The API request URI
68
+     */
69
+    protected $api_url = 'https://www.google.com/recaptcha/api/siteverify';
70
+
71
+    /**
72
+     * ReCaptchaBuilder constructor.
73
+     *
74
+     * @param string      $api_site_key
75
+     * @param string      $api_secret_key
76
+     * @param null|string $version
77
+     * @param int|null    $curl_timeout
78
+     */
79
+    public function __construct(
80
+        string $api_site_key,
81
+        string $api_secret_key,
82
+        ?string $version = self::DEFAULT_API_VERSION,
83
+        ?int $curl_timeout = self::DEFAULT_CURL_TIMEOUT
84
+    ) {
85
+
86
+        $this->setApiSiteKey($api_site_key);
87
+        $this->setApiSecretKey($api_secret_key);
88
+        $this->setVersion($version);
89
+        $this->setCurlTimeout($curl_timeout);
90
+        $this->setSkipByIp($this->skipByIp());
91
+    }
92
+
93
+    /**
94
+     * @param string $api_site_key
95
+     *
96
+     * @return ReCaptchaBuilder
97
+     */
98
+    public function setApiSiteKey(string $api_site_key): ReCaptchaBuilder {
99
+
100
+        $this->api_site_key = $api_site_key;
101
+
102
+        return $this;
103
+    }
104
+
105
+    /**
106
+     * @param string $api_secret_key
107
+     *
108
+     * @return ReCaptchaBuilder
109
+     */
110
+    public function setApiSecretKey(string $api_secret_key): ReCaptchaBuilder {
111
+
112
+        $this->api_secret_key = $api_secret_key;
113
+
114
+        return $this;
115
+    }
116
+
117
+    /**
118
+     * @param int|null $curl_timeout
119
+     *
120
+     * @return ReCaptchaBuilder
121
+     */
122
+    public function setCurlTimeout(?int $curl_timeout = null): ReCaptchaBuilder {
123
+
124
+        if($curl_timeout === null) {
125
+            $curl_timeout = config('recaptcha.curl_timeout', ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT);
126
+        }
127
+        $this->curl_timeout = $curl_timeout;
128
+
129
+        return $this;
130
+    }
131
+
132
+    /**
133
+     * @return int
134
+     */
135
+    public function getCurlTimeout(): int {
136
+
137
+        return $this->curl_timeout;
138
+    }
139
+
140
+    /**
141
+     * @param string $version
142
+     *
143
+     * @return ReCaptchaBuilder
144
+     */
145
+    public function setVersion(string $version): ReCaptchaBuilder {
146
+
147
+        $this->version = $version;
148
+
149
+        return $this;
150
+    }
151
+
152
+    /**
153
+     * @return string
154
+     */
155
+    public function getVersion(): string {
156
+
157
+        return $this->version;
158
+    }
159
+
160
+    /**
161
+     * @param bool $skip_by_ip
162
+     *
163
+     * @return ReCaptchaBuilder
164
+     */
165
+    public function setSkipByIp(bool $skip_by_ip): ReCaptchaBuilder {
166
+
167
+        $this->skip_by_ip = $skip_by_ip;
168
+
169
+        return $this;
170
+    }
171
+
172
+    /**
173
+     * @return array|mixed
174
+     */
175
+    public function getIpWhitelist() {
176
+
177
+        $whitelist = config('recaptcha.skip_ip', []);
178
+
179
+        if (!is_array($whitelist)) {
180
+            $whitelist = explode(',', $whitelist);
181
+        }
182
+
183
+        return $whitelist;
184
+    }
185
+
186
+    /**
187
+     * Checks whether the user IP address is among IPs "to be skipped"
188
+     *
189
+     * @return boolean
190
+     */
191
+    public function skipByIp(): bool {
192
+
193
+        return (in_array(request()->ip(), $this->getIpWhitelist()));
194
+    }
195
+
196
+    /**
197
+     * Write script HTML tag in you HTML code
198
+     * Insert before </head> tag
199
+     *
200
+     * @param string|null $formId
201
+     * @param array|null  $configuration
202
+     *
203
+     * @return string
204
+     * @throws Exception
205
+     */
206
+    public function htmlScriptTagJsApi(?string $formId = '', ?array $configuration = []): string {
207
+
208
+        if ($this->skip_by_ip) {
209
+            return '';
210
+        }
211
+
212
+        switch ($this->version) {
213
+            case 'v3':
214
+                $html = "<script src=\"https://www.google.com/recaptcha/api.js?render={$this->api_site_key}\"></script>";
215
+                break;
216
+            default:
217
+                $html = "<script src=\"https://www.google.com/recaptcha/api.js\" async defer></script>";
218
+        }
219
+
220
+        if ($this->version == 'invisible') {
221
+            if (!$formId) {
222
+                throw new Exception("formId required", 1);
223
+            }
224
+            $html .= '<script>
225 225
 		       function biscolabLaravelReCaptcha(token) {
226 226
 		         document.getElementById("' . $formId . '").submit();
227 227
 		       }
228 228
 		     </script>';
229
-		}
230
-		elseif ($this->version == 'v3') {
229
+        }
230
+        elseif ($this->version == 'v3') {
231 231
 
232
-			$action = Arr::get($configuration, 'action', 'homepage');
232
+            $action = Arr::get($configuration, 'action', 'homepage');
233 233
 
234
-			$js_custom_validation = Arr::get($configuration, 'custom_validation', '');
234
+            $js_custom_validation = Arr::get($configuration, 'custom_validation', '');
235 235
 
236
-			// Check if set custom_validation. That function will override default fetch validation function
237
-			if ($js_custom_validation) {
236
+            // Check if set custom_validation. That function will override default fetch validation function
237
+            if ($js_custom_validation) {
238 238
 
239
-				$validate_function = ($js_custom_validation) ? "{$js_custom_validation}(token);" : '';
240
-			}
241
-			else {
239
+                $validate_function = ($js_custom_validation) ? "{$js_custom_validation}(token);" : '';
240
+            }
241
+            else {
242 242
 
243
-				$js_then_callback = Arr::get($configuration, 'callback_then', '');
244
-				$js_callback_catch = Arr::get($configuration, 'callback_catch', '');
243
+                $js_then_callback = Arr::get($configuration, 'callback_then', '');
244
+                $js_callback_catch = Arr::get($configuration, 'callback_catch', '');
245 245
 
246
-				$js_then_callback = ($js_then_callback) ? "{$js_then_callback}(response)" : '';
247
-				$js_callback_catch = ($js_callback_catch) ? "{$js_callback_catch}(err)" : '';
246
+                $js_then_callback = ($js_then_callback) ? "{$js_then_callback}(response)" : '';
247
+                $js_callback_catch = ($js_callback_catch) ? "{$js_callback_catch}(err)" : '';
248 248
 
249
-				$validate_function = "
249
+                $validate_function = "
250 250
                 fetch('/" . config('recaptcha.default_validation_route',
251
-						'biscolab-recaptcha/validate') . "?" . config('recaptcha.default_token_parameter_name',
252
-						'token') . "=' + token, {
251
+                        'biscolab-recaptcha/validate') . "?" . config('recaptcha.default_token_parameter_name',
252
+                        'token') . "=' + token, {
253 253
                     headers: {
254 254
                         \"X-Requested-With\": \"XMLHttpRequest\",
255 255
                         \"X-CSRF-TOKEN\": csrfToken.content
@@ -261,9 +261,9 @@  discard block
 block discarded – undo
261 261
                 .catch(function(err) {
262 262
                     {$js_callback_catch}
263 263
                 });";
264
-			}
264
+            }
265 265
 
266
-			$html .= "<script>
266
+            $html .= "<script>
267 267
                     var csrfToken = document.head.querySelector('meta[name=\"csrf-token\"]');
268 268
                   grecaptcha.ready(function() {
269 269
                       grecaptcha.execute('{$this->api_site_key}', {action: '{$action}'}).then(function(token) {
@@ -271,90 +271,90 @@  discard block
 block discarded – undo
271 271
                       });
272 272
                   });
273 273
 		     </script>";
274
-		}
275
-
276
-		return $html;
277
-	}
278
-
279
-	/**
280
-	 * @param array|null $configuration
281
-	 *
282
-	 * @return string
283
-	 */
284
-	public function htmlScriptTagJsApiV3(?array $configuration = []): string {
285
-
286
-		return $this->htmlScriptTagJsApi('', $configuration);
287
-	}
288
-
289
-	/**
290
-	 * Call out to reCAPTCHA and process the response
291
-	 *
292
-	 * @param string $response
293
-	 *
294
-	 * @return boolean|array
295
-	 */
296
-	public function validate($response) {
297
-
298
-		if ($this->skip_by_ip) {
299
-			if ($this->returnArray()) {
300
-				// Add 'skip_by_ip' field to response
301
-				return [
302
-					'skip_by_ip' => true,
303
-					'score'      => 0.9,
304
-					'success'    => true
305
-				];
306
-			}
307
-
308
-			return true;
309
-		}
310
-
311
-		$params = http_build_query([
312
-			'secret'   => $this->api_secret_key,
313
-			'remoteip' => request()->getClientIp(),
314
-			'response' => $response,
315
-		]);
316
-
317
-		$url = $this->api_url . '?' . $params;
318
-
319
-		if (function_exists('curl_version')) {
320
-			$curl = curl_init($url);
321
-			curl_setopt($curl, CURLOPT_HEADER, false);
322
-			curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
323
-			curl_setopt($curl, CURLOPT_TIMEOUT, $this->curl_timeout);
324
-			curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
325
-			$curl_response = curl_exec($curl);
326
-		}
327
-		else {
328
-			$curl_response = file_get_contents($url);
329
-		}
330
-
331
-		if (is_null($curl_response) || empty($curl_response)) {
332
-			if ($this->returnArray()) {
333
-				// Add 'error' field to response
334
-				return [
335
-					'error'   => 'cURL response empty',
336
-					'score'   => 0.1,
337
-					'success' => false
338
-				];
339
-			}
340
-
341
-			return false;
342
-		}
343
-		$response = json_decode(trim($curl_response), true);
344
-
345
-		if ($this->returnArray()) {
346
-			return $response;
347
-		}
348
-
349
-		return $response['success'];
350
-
351
-	}
352
-
353
-	/**
354
-	 * @return bool
355
-	 */
356
-	protected function returnArray(): bool {
357
-
358
-		return ($this->version == 'v3');
359
-	}
274
+        }
275
+
276
+        return $html;
277
+    }
278
+
279
+    /**
280
+     * @param array|null $configuration
281
+     *
282
+     * @return string
283
+     */
284
+    public function htmlScriptTagJsApiV3(?array $configuration = []): string {
285
+
286
+        return $this->htmlScriptTagJsApi('', $configuration);
287
+    }
288
+
289
+    /**
290
+     * Call out to reCAPTCHA and process the response
291
+     *
292
+     * @param string $response
293
+     *
294
+     * @return boolean|array
295
+     */
296
+    public function validate($response) {
297
+
298
+        if ($this->skip_by_ip) {
299
+            if ($this->returnArray()) {
300
+                // Add 'skip_by_ip' field to response
301
+                return [
302
+                    'skip_by_ip' => true,
303
+                    'score'      => 0.9,
304
+                    'success'    => true
305
+                ];
306
+            }
307
+
308
+            return true;
309
+        }
310
+
311
+        $params = http_build_query([
312
+            'secret'   => $this->api_secret_key,
313
+            'remoteip' => request()->getClientIp(),
314
+            'response' => $response,
315
+        ]);
316
+
317
+        $url = $this->api_url . '?' . $params;
318
+
319
+        if (function_exists('curl_version')) {
320
+            $curl = curl_init($url);
321
+            curl_setopt($curl, CURLOPT_HEADER, false);
322
+            curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
323
+            curl_setopt($curl, CURLOPT_TIMEOUT, $this->curl_timeout);
324
+            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
325
+            $curl_response = curl_exec($curl);
326
+        }
327
+        else {
328
+            $curl_response = file_get_contents($url);
329
+        }
330
+
331
+        if (is_null($curl_response) || empty($curl_response)) {
332
+            if ($this->returnArray()) {
333
+                // Add 'error' field to response
334
+                return [
335
+                    'error'   => 'cURL response empty',
336
+                    'score'   => 0.1,
337
+                    'success' => false
338
+                ];
339
+            }
340
+
341
+            return false;
342
+        }
343
+        $response = json_decode(trim($curl_response), true);
344
+
345
+        if ($this->returnArray()) {
346
+            return $response;
347
+        }
348
+
349
+        return $response['success'];
350
+
351
+    }
352
+
353
+    /**
354
+     * @return bool
355
+     */
356
+    protected function returnArray(): bool {
357
+
358
+        return ($this->version == 'v3');
359
+    }
360 360
 }
361 361
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 	 */
122 122
 	public function setCurlTimeout(?int $curl_timeout = null): ReCaptchaBuilder {
123 123
 
124
-		if($curl_timeout === null) {
124
+		if ($curl_timeout === null) {
125 125
 			$curl_timeout = config('recaptcha.curl_timeout', ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT);
126 126
 		}
127 127
 		$this->curl_timeout = $curl_timeout;
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
 			}
224 224
 			$html .= '<script>
225 225
 		       function biscolabLaravelReCaptcha(token) {
226
-		         document.getElementById("' . $formId . '").submit();
226
+		         document.getElementById("' . $formId.'").submit();
227 227
 		       }
228 228
 		     </script>';
229 229
 		}
@@ -248,8 +248,8 @@  discard block
 block discarded – undo
248 248
 
249 249
 				$validate_function = "
250 250
                 fetch('/" . config('recaptcha.default_validation_route',
251
-						'biscolab-recaptcha/validate') . "?" . config('recaptcha.default_token_parameter_name',
252
-						'token') . "=' + token, {
251
+						'biscolab-recaptcha/validate')."?".config('recaptcha.default_token_parameter_name',
252
+						'token')."=' + token, {
253 253
                     headers: {
254 254
                         \"X-Requested-With\": \"XMLHttpRequest\",
255 255
                         \"X-CSRF-TOKEN\": csrfToken.content
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
 			'response' => $response,
315 315
 		]);
316 316
 
317
-		$url = $this->api_url . '?' . $params;
317
+		$url = $this->api_url.'?'.$params;
318 318
 
319 319
 		if (function_exists('curl_version')) {
320 320
 			$curl = curl_init($url);
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -226,8 +226,7 @@  discard block
 block discarded – undo
226 226
 		         document.getElementById("' . $formId . '").submit();
227 227
 		       }
228 228
 		     </script>';
229
-		}
230
-		elseif ($this->version == 'v3') {
229
+		} elseif ($this->version == 'v3') {
231 230
 
232 231
 			$action = Arr::get($configuration, 'action', 'homepage');
233 232
 
@@ -237,8 +236,7 @@  discard block
 block discarded – undo
237 236
 			if ($js_custom_validation) {
238 237
 
239 238
 				$validate_function = ($js_custom_validation) ? "{$js_custom_validation}(token);" : '';
240
-			}
241
-			else {
239
+			} else {
242 240
 
243 241
 				$js_then_callback = Arr::get($configuration, 'callback_then', '');
244 242
 				$js_callback_catch = Arr::get($configuration, 'callback_catch', '');
@@ -323,8 +321,7 @@  discard block
 block discarded – undo
323 321
 			curl_setopt($curl, CURLOPT_TIMEOUT, $this->curl_timeout);
324 322
 			curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
325 323
 			$curl_response = curl_exec($curl);
326
-		}
327
-		else {
324
+		} else {
328 325
 			$curl_response = file_get_contents($url);
329 326
 		}
330 327
 
Please login to merge, or discard this patch.
tests/ReCaptchaConfigurationTest.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -22,48 +22,48 @@
 block discarded – undo
22 22
  */
23 23
 class ReCaptchaConfigurationTest extends TestCase {
24 24
 
25
-	/**
26
-	 * @var ReCaptchaBuilder
27
-	 */
28
-	protected $recaptcha;
25
+    /**
26
+     * @var ReCaptchaBuilder
27
+     */
28
+    protected $recaptcha;
29 29
 
30
-	/**
31
-	 * @test
32
-	 */
33
-	public function testSkipIpWhiteListIsArray() {
30
+    /**
31
+     * @test
32
+     */
33
+    public function testSkipIpWhiteListIsArray() {
34 34
 
35
-		$ip_whitelist = $this->recaptcha->getIpWhitelist();
36
-		$this->assertTrue(is_array($ip_whitelist));
37
-		$this->assertCount(2, $ip_whitelist);
38
-	}
35
+        $ip_whitelist = $this->recaptcha->getIpWhitelist();
36
+        $this->assertTrue(is_array($ip_whitelist));
37
+        $this->assertCount(2, $ip_whitelist);
38
+    }
39 39
 
40
-	/**
41
-	 * @test
42
-	 */
43
-	public function testCurlTimeoutIsSet() {
44
-		$this->assertEquals(3, $this->recaptcha->getCurlTimeout());
45
-	}
40
+    /**
41
+     * @test
42
+     */
43
+    public function testCurlTimeoutIsSet() {
44
+        $this->assertEquals(3, $this->recaptcha->getCurlTimeout());
45
+    }
46 46
 
47
-	/**
48
-	 * Define environment setup.
49
-	 *
50
-	 * @param  \Illuminate\Foundation\Application $app
51
-	 *
52
-	 * @return void
53
-	 */
54
-	protected function getEnvironmentSetUp($app) {
47
+    /**
48
+     * Define environment setup.
49
+     *
50
+     * @param  \Illuminate\Foundation\Application $app
51
+     *
52
+     * @return void
53
+     */
54
+    protected function getEnvironmentSetUp($app) {
55 55
 
56
-		$app['config']->set('recaptcha.skip_ip', '10.0.0.1,10.0.0.2');
57
-		$app['config']->set('recaptcha.curl_timeout', 3);
58
-	}
56
+        $app['config']->set('recaptcha.skip_ip', '10.0.0.1,10.0.0.2');
57
+        $app['config']->set('recaptcha.curl_timeout', 3);
58
+    }
59 59
 
60
-	/**
61
-	 * Setup the test environment.
62
-	 */
63
-	protected function setUp(): void {
60
+    /**
61
+     * Setup the test environment.
62
+     */
63
+    protected function setUp(): void {
64 64
 
65
-		parent::setUp(); // TODO: Change the autogenerated stub
65
+        parent::setUp(); // TODO: Change the autogenerated stub
66 66
 
67
-		$this->recaptcha = new ReCaptchaBuilderV2('api_site_key', 'api_secret_key');
68
-	}
67
+        $this->recaptcha = new ReCaptchaBuilderV2('api_site_key', 'api_secret_key');
68
+    }
69 69
 }
70 70
\ No newline at end of file
Please login to merge, or discard this patch.
tests/ReCaptchaTest.php 1 patch
Indentation   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -22,97 +22,97 @@
 block discarded – undo
22 22
  */
23 23
 class ReCaptchaTest extends TestCase {
24 24
 
25
-	/**
26
-	 * @var ReCaptchaBuilderInvisible
27
-	 */
28
-	protected $recaptcha_invisible = null;
29
-
30
-	/**
31
-	 * @var ReCaptchaBuilderV2
32
-	 */
33
-	protected $recaptcha_v2 = null;
34
-
35
-	/**
36
-	 * @var ReCaptchaBuilderV3
37
-	 */
38
-	protected $recaptcha_v3 = null;
39
-
40
-	/**
41
-	 * @tests
42
-	 */
43
-	public function testHtmlScriptTagJsApiGetHtmlScriptTag() {
44
-
45
-		$r = ReCaptcha::htmlScriptTagJsApi();
46
-		$this->assertEquals('<script src="https://www.google.com/recaptcha/api.js" async defer></script>', $r);
47
-	}
48
-
49
-	/**
50
-	 * @test
51
-	 */
52
-	public function testReCaptchaInvisibleHtmlFormButtonDefault() {
53
-
54
-		$recaptcha = $this->recaptcha_invisible;
55
-		$html_button = $recaptcha->htmlFormButton();
56
-		$this->assertEquals('<button class="g-recaptcha" data-sitekey="api_site_key" data-callback="biscolabLaravelReCaptcha">Submit</button>',
57
-			$html_button);
58
-	}
59
-
60
-	/**
61
-	 * @test
62
-	 */
63
-	public function testReCaptchaInvisibleHtmlFormButtonCustom() {
64
-
65
-		$recaptcha = $this->recaptcha_invisible;
66
-		$html_button = $recaptcha->htmlFormButton('Custom Text');
67
-		$this->assertEquals('<button class="g-recaptcha" data-sitekey="api_site_key" data-callback="biscolabLaravelReCaptcha">Custom Text</button>',
68
-			$html_button);
69
-	}
70
-
71
-	/**
72
-	 * @test
73
-	 */
74
-	public function testReCaptchaV2HtmlFormSnippet() {
75
-
76
-		$recaptcha = $this->recaptcha_v2;
77
-		$html_snippet = $recaptcha->htmlFormSnippet();
78
-		$this->assertEquals('<div class="g-recaptcha" data-sitekey="api_site_key"></div>', $html_snippet);
79
-	}
80
-
81
-	/**
82
-	 * @test
83
-	 * @expectedException     \Error
84
-	 */
85
-	public function testReCaptchaInvisibleHtmlFormSnippetShouldThrowError() {
86
-
87
-		$this->recaptcha_invisible->htmlFormSnippet();
88
-	}
89
-
90
-	/**
91
-	 * @test
92
-	 */
93
-	public function testDefaultCurlTimeout() {
94
-
95
-		$this->assertEquals($this->recaptcha_invisible->getCurlTimeout(), ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT);
96
-		$this->assertEquals($this->recaptcha_v2->getCurlTimeout(), ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT);
97
-		$this->assertEquals($this->recaptcha_v3->getCurlTimeout(), ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT);
98
-	}
99
-
100
-	/**
101
-	 * @test
102
-	 * @expectedException     \Error
103
-	 */
104
-	public function testReCaptchaV2htmlFormButtonShouldThrowError() {
105
-
106
-		$this->recaptcha_v2->htmlFormButton();
107
-	}
108
-
109
-	protected function setUp(): void {
110
-
111
-		parent::setUp(); // TODO: Change the autogenerated stub
112
-
113
-		$this->recaptcha_invisible = new ReCaptchaBuilderInvisible('api_site_key', 'api_secret_key');
114
-		$this->recaptcha_v2 = new ReCaptchaBuilderV2('api_site_key', 'api_secret_key');
115
-		$this->recaptcha_v3 = new ReCaptchaBuilderV3('api_site_key', 'api_secret_key');
116
-
117
-	}
25
+    /**
26
+     * @var ReCaptchaBuilderInvisible
27
+     */
28
+    protected $recaptcha_invisible = null;
29
+
30
+    /**
31
+     * @var ReCaptchaBuilderV2
32
+     */
33
+    protected $recaptcha_v2 = null;
34
+
35
+    /**
36
+     * @var ReCaptchaBuilderV3
37
+     */
38
+    protected $recaptcha_v3 = null;
39
+
40
+    /**
41
+     * @tests
42
+     */
43
+    public function testHtmlScriptTagJsApiGetHtmlScriptTag() {
44
+
45
+        $r = ReCaptcha::htmlScriptTagJsApi();
46
+        $this->assertEquals('<script src="https://www.google.com/recaptcha/api.js" async defer></script>', $r);
47
+    }
48
+
49
+    /**
50
+     * @test
51
+     */
52
+    public function testReCaptchaInvisibleHtmlFormButtonDefault() {
53
+
54
+        $recaptcha = $this->recaptcha_invisible;
55
+        $html_button = $recaptcha->htmlFormButton();
56
+        $this->assertEquals('<button class="g-recaptcha" data-sitekey="api_site_key" data-callback="biscolabLaravelReCaptcha">Submit</button>',
57
+            $html_button);
58
+    }
59
+
60
+    /**
61
+     * @test
62
+     */
63
+    public function testReCaptchaInvisibleHtmlFormButtonCustom() {
64
+
65
+        $recaptcha = $this->recaptcha_invisible;
66
+        $html_button = $recaptcha->htmlFormButton('Custom Text');
67
+        $this->assertEquals('<button class="g-recaptcha" data-sitekey="api_site_key" data-callback="biscolabLaravelReCaptcha">Custom Text</button>',
68
+            $html_button);
69
+    }
70
+
71
+    /**
72
+     * @test
73
+     */
74
+    public function testReCaptchaV2HtmlFormSnippet() {
75
+
76
+        $recaptcha = $this->recaptcha_v2;
77
+        $html_snippet = $recaptcha->htmlFormSnippet();
78
+        $this->assertEquals('<div class="g-recaptcha" data-sitekey="api_site_key"></div>', $html_snippet);
79
+    }
80
+
81
+    /**
82
+     * @test
83
+     * @expectedException     \Error
84
+     */
85
+    public function testReCaptchaInvisibleHtmlFormSnippetShouldThrowError() {
86
+
87
+        $this->recaptcha_invisible->htmlFormSnippet();
88
+    }
89
+
90
+    /**
91
+     * @test
92
+     */
93
+    public function testDefaultCurlTimeout() {
94
+
95
+        $this->assertEquals($this->recaptcha_invisible->getCurlTimeout(), ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT);
96
+        $this->assertEquals($this->recaptcha_v2->getCurlTimeout(), ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT);
97
+        $this->assertEquals($this->recaptcha_v3->getCurlTimeout(), ReCaptchaBuilder::DEFAULT_CURL_TIMEOUT);
98
+    }
99
+
100
+    /**
101
+     * @test
102
+     * @expectedException     \Error
103
+     */
104
+    public function testReCaptchaV2htmlFormButtonShouldThrowError() {
105
+
106
+        $this->recaptcha_v2->htmlFormButton();
107
+    }
108
+
109
+    protected function setUp(): void {
110
+
111
+        parent::setUp(); // TODO: Change the autogenerated stub
112
+
113
+        $this->recaptcha_invisible = new ReCaptchaBuilderInvisible('api_site_key', 'api_secret_key');
114
+        $this->recaptcha_v2 = new ReCaptchaBuilderV2('api_site_key', 'api_secret_key');
115
+        $this->recaptcha_v3 = new ReCaptchaBuilderV3('api_site_key', 'api_secret_key');
116
+
117
+    }
118 118
 }
119 119
\ No newline at end of file
Please login to merge, or discard this patch.
tests/ReCaptchaV3Test.php 1 patch
Indentation   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -20,101 +20,101 @@
 block discarded – undo
20 20
  */
21 21
 class ReCaptchaV3Test extends TestCase {
22 22
 
23
-	protected $recaptcha_v3 = null;
24
-
25
-	/**
26
-	 * @test
27
-	 */
28
-	public function testGetApiVersion() {
29
-
30
-		$this->assertEquals($this->recaptcha_v3->getVersion(), 'v3');
31
-	}
32
-
33
-	/**
34
-	 * @test
35
-	 */
36
-	public function testHtmlScriptTagJsApiV3GetHtmlScriptTag() {
37
-
38
-		$r = $this->recaptcha_v3->htmlScriptTagJsApiV3();
39
-		$this->assertRegexp('/csrfToken/', $r);
40
-	}
41
-
42
-	/**
43
-	 * @test
44
-	 */
45
-	public function testAction() {
46
-
47
-		$r = $this->recaptcha_v3->htmlScriptTagJsApiV3(['action' => 'someAction']);
48
-		$this->assertRegexp('/someAction/', $r);
49
-	}
50
-
51
-	/**
52
-	 * @test
53
-	 */
54
-	public function testFetchCallbackFunction() {
55
-
56
-		$r = $this->recaptcha_v3->htmlScriptTagJsApiV3(['callback_then' => 'functionCallbackThen']);
57
-		$this->assertRegexp('/functionCallbackThen\(response\)/', $r);
58
-	}
59
-
60
-	/**
61
-	 * @test
62
-	 */
63
-	public function testcCatchCallbackFunction() {
64
-
65
-		$r = $this->recaptcha_v3->htmlScriptTagJsApiV3(['callback_catch' => 'functionCallbackCatch']);
66
-		$this->assertRegexp('/functionCallbackCatch\(err\)/', $r);
67
-	}
68
-
69
-	/**
70
-	 * @test
71
-	 */
72
-	public function testCustomValidationFunction() {
73
-
74
-		$r = $this->recaptcha_v3->htmlScriptTagJsApiV3(['custom_validation' => 'functionCustomValidation']);
75
-		$this->assertRegexp('/functionCustomValidation\(token\)/', $r);
76
-	}
77
-
78
-	/**
79
-	 * @test
80
-	 */
81
-	public function testValidateController() {
82
-
83
-		$controller = App::make(ReCaptchaController::class);
84
-		$return = $controller->validateV3();
85
-
86
-		$this->assertArrayHasKey("success", $return);
87
-		$this->assertArrayHasKey("error-codes", $return);
88
-	}
89
-
90
-	/**
91
-	 * @test
92
-	 */
93
-	public function testCurlTimeoutIsSet() {
94
-		$this->assertEquals($this->recaptcha_v3->getCurlTimeout(), 3);
95
-	}
96
-
97
-	/**
98
-	 * Define environment setup.
99
-	 *
100
-	 * @param  \Illuminate\Foundation\Application $app
101
-	 *
102
-	 * @return void
103
-	 */
104
-	protected function getEnvironmentSetUp($app) {
105
-
106
-		$app['config']->set('recaptcha.version', 'v3');
107
-		$app['config']->set('recaptcha.curl_timeout', 3);
108
-	}
109
-
110
-	/**
111
-	 * Setup the test environment.
112
-	 */
113
-	protected function setUp(): void {
114
-
115
-		parent::setUp(); // TODO: Change the autogenerated stub
116
-
117
-		$this->recaptcha_v3 = new ReCaptchaBuilderV3('api_site_key', 'api_secret_key');
118
-
119
-	}
23
+    protected $recaptcha_v3 = null;
24
+
25
+    /**
26
+     * @test
27
+     */
28
+    public function testGetApiVersion() {
29
+
30
+        $this->assertEquals($this->recaptcha_v3->getVersion(), 'v3');
31
+    }
32
+
33
+    /**
34
+     * @test
35
+     */
36
+    public function testHtmlScriptTagJsApiV3GetHtmlScriptTag() {
37
+
38
+        $r = $this->recaptcha_v3->htmlScriptTagJsApiV3();
39
+        $this->assertRegexp('/csrfToken/', $r);
40
+    }
41
+
42
+    /**
43
+     * @test
44
+     */
45
+    public function testAction() {
46
+
47
+        $r = $this->recaptcha_v3->htmlScriptTagJsApiV3(['action' => 'someAction']);
48
+        $this->assertRegexp('/someAction/', $r);
49
+    }
50
+
51
+    /**
52
+     * @test
53
+     */
54
+    public function testFetchCallbackFunction() {
55
+
56
+        $r = $this->recaptcha_v3->htmlScriptTagJsApiV3(['callback_then' => 'functionCallbackThen']);
57
+        $this->assertRegexp('/functionCallbackThen\(response\)/', $r);
58
+    }
59
+
60
+    /**
61
+     * @test
62
+     */
63
+    public function testcCatchCallbackFunction() {
64
+
65
+        $r = $this->recaptcha_v3->htmlScriptTagJsApiV3(['callback_catch' => 'functionCallbackCatch']);
66
+        $this->assertRegexp('/functionCallbackCatch\(err\)/', $r);
67
+    }
68
+
69
+    /**
70
+     * @test
71
+     */
72
+    public function testCustomValidationFunction() {
73
+
74
+        $r = $this->recaptcha_v3->htmlScriptTagJsApiV3(['custom_validation' => 'functionCustomValidation']);
75
+        $this->assertRegexp('/functionCustomValidation\(token\)/', $r);
76
+    }
77
+
78
+    /**
79
+     * @test
80
+     */
81
+    public function testValidateController() {
82
+
83
+        $controller = App::make(ReCaptchaController::class);
84
+        $return = $controller->validateV3();
85
+
86
+        $this->assertArrayHasKey("success", $return);
87
+        $this->assertArrayHasKey("error-codes", $return);
88
+    }
89
+
90
+    /**
91
+     * @test
92
+     */
93
+    public function testCurlTimeoutIsSet() {
94
+        $this->assertEquals($this->recaptcha_v3->getCurlTimeout(), 3);
95
+    }
96
+
97
+    /**
98
+     * Define environment setup.
99
+     *
100
+     * @param  \Illuminate\Foundation\Application $app
101
+     *
102
+     * @return void
103
+     */
104
+    protected function getEnvironmentSetUp($app) {
105
+
106
+        $app['config']->set('recaptcha.version', 'v3');
107
+        $app['config']->set('recaptcha.curl_timeout', 3);
108
+    }
109
+
110
+    /**
111
+     * Setup the test environment.
112
+     */
113
+    protected function setUp(): void {
114
+
115
+        parent::setUp(); // TODO: Change the autogenerated stub
116
+
117
+        $this->recaptcha_v3 = new ReCaptchaBuilderV3('api_site_key', 'api_secret_key');
118
+
119
+    }
120 120
 }
121 121
\ No newline at end of file
Please login to merge, or discard this patch.