Completed
Branch feature/test_config_facade_in_... (4dbc26)
by Roberto
07:01
created
tests/TestCase.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -20,29 +20,29 @@
 block discarded – undo
20 20
  */
21 21
 class TestCase extends OrchestraTestCase {
22 22
 
23
-	/**
24
-	 * Load package alias
25
-	 *
26
-	 * @param  \Illuminate\Foundation\Application $app
27
-	 *
28
-	 * @return array
29
-	 */
30
-	protected function getPackageAliases($app) {
23
+    /**
24
+     * Load package alias
25
+     *
26
+     * @param  \Illuminate\Foundation\Application $app
27
+     *
28
+     * @return array
29
+     */
30
+    protected function getPackageAliases($app) {
31 31
 
32
-		return [
33
-			'ReCaptcha' => ReCaptcha::class,
34
-		];
35
-	}
32
+        return [
33
+            'ReCaptcha' => ReCaptcha::class,
34
+        ];
35
+    }
36 36
 
37
-	/**
38
-	 * Load package service provider
39
-	 *
40
-	 * @param \Illuminate\Foundation\Application $app
41
-	 *
42
-	 * @return array
43
-	 */
44
-	protected function getPackageProviders($app) {
37
+    /**
38
+     * Load package service provider
39
+     *
40
+     * @param \Illuminate\Foundation\Application $app
41
+     *
42
+     * @return array
43
+     */
44
+    protected function getPackageProviders($app) {
45 45
 
46
-		return [ReCaptchaServiceProvider::class];
47
-	}
46
+        return [ReCaptchaServiceProvider::class];
47
+    }
48 48
 }
Please login to merge, or discard this patch.
tests/ReCaptchaTest.php 1 patch
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -20,73 +20,73 @@
 block discarded – undo
20 20
  */
21 21
 class ReCaptchaTest extends TestCase {
22 22
 
23
-	protected $recaptcha_invisible = null;
23
+    protected $recaptcha_invisible = null;
24 24
 
25
-	protected $recaptcha_v2        = null;
25
+    protected $recaptcha_v2        = null;
26 26
 
27
-	/**
28
-	 * @tests
29
-	 */
30
-	public function testHtmlScriptTagJsApiGetHtmlScriptTag() {
27
+    /**
28
+     * @tests
29
+     */
30
+    public function testHtmlScriptTagJsApiGetHtmlScriptTag() {
31 31
 
32
-		$r = ReCaptcha::htmlScriptTagJsApi();
33
-		$this->assertEquals('<script src="https://www.google.com/recaptcha/api.js" async defer></script>', $r);
34
-	}
32
+        $r = ReCaptcha::htmlScriptTagJsApi();
33
+        $this->assertEquals('<script src="https://www.google.com/recaptcha/api.js" async defer></script>', $r);
34
+    }
35 35
 
36
-	/**
37
-	 * @test
38
-	 */
39
-	public function testReCaptchaInvisibleHtmlFormButtonDefault() {
36
+    /**
37
+     * @test
38
+     */
39
+    public function testReCaptchaInvisibleHtmlFormButtonDefault() {
40 40
 
41
-		$recaptcha = $this->recaptcha_invisible;
42
-		$html_button = $recaptcha->htmlFormButton();
43
-		$this->assertEquals('<button class="g-recaptcha" data-sitekey="api_site_key" data-callback="biscolabLaravelReCaptcha">Submit</button>', $html_button);
44
-	}
41
+        $recaptcha = $this->recaptcha_invisible;
42
+        $html_button = $recaptcha->htmlFormButton();
43
+        $this->assertEquals('<button class="g-recaptcha" data-sitekey="api_site_key" data-callback="biscolabLaravelReCaptcha">Submit</button>', $html_button);
44
+    }
45 45
 
46
-	/**
47
-	 * @test
48
-	 */
49
-	public function testReCaptchaInvisibleHtmlFormButtonCustom() {
46
+    /**
47
+     * @test
48
+     */
49
+    public function testReCaptchaInvisibleHtmlFormButtonCustom() {
50 50
 
51
-		$recaptcha = $this->recaptcha_invisible;
52
-		$html_button = $recaptcha->htmlFormButton('Custom Text');
53
-		$this->assertEquals('<button class="g-recaptcha" data-sitekey="api_site_key" data-callback="biscolabLaravelReCaptcha">Custom Text</button>', $html_button);
54
-	}
51
+        $recaptcha = $this->recaptcha_invisible;
52
+        $html_button = $recaptcha->htmlFormButton('Custom Text');
53
+        $this->assertEquals('<button class="g-recaptcha" data-sitekey="api_site_key" data-callback="biscolabLaravelReCaptcha">Custom Text</button>', $html_button);
54
+    }
55 55
 
56
-	/**
57
-	 * @test
58
-	 */
59
-	public function testReCaptchaV2HtmlFormSnippet() {
56
+    /**
57
+     * @test
58
+     */
59
+    public function testReCaptchaV2HtmlFormSnippet() {
60 60
 
61
-		$recaptcha = $this->recaptcha_v2;
62
-		$html_snippet = $recaptcha->htmlFormSnippet();
63
-		$this->assertEquals('<div class="g-recaptcha" data-sitekey="api_site_key"></div>', $html_snippet);
64
-	}
61
+        $recaptcha = $this->recaptcha_v2;
62
+        $html_snippet = $recaptcha->htmlFormSnippet();
63
+        $this->assertEquals('<div class="g-recaptcha" data-sitekey="api_site_key"></div>', $html_snippet);
64
+    }
65 65
 
66
-	/**
67
-	 * @test
68
-	 * @expectedException     \Error
69
-	 */
70
-	public function testReCaptchaInvisibleHtmlFormSnippetShouldThrowError() {
66
+    /**
67
+     * @test
68
+     * @expectedException     \Error
69
+     */
70
+    public function testReCaptchaInvisibleHtmlFormSnippetShouldThrowError() {
71 71
 
72
-		$this->recaptcha_invisible->htmlFormSnippet();
73
-	}
72
+        $this->recaptcha_invisible->htmlFormSnippet();
73
+    }
74 74
 
75
-	/**
76
-	 * @test
77
-	 * @expectedException     \Error
78
-	 */
79
-	public function testReCaptchaV2htmlFormButtonShouldThrowError() {
75
+    /**
76
+     * @test
77
+     * @expectedException     \Error
78
+     */
79
+    public function testReCaptchaV2htmlFormButtonShouldThrowError() {
80 80
 
81
-		$this->recaptcha_v2->htmlFormButton();
82
-	}
81
+        $this->recaptcha_v2->htmlFormButton();
82
+    }
83 83
 
84
-	protected function setUp() {
84
+    protected function setUp() {
85 85
 
86
-		parent::setUp(); // TODO: Change the autogenerated stub
86
+        parent::setUp(); // TODO: Change the autogenerated stub
87 87
 
88
-		$this->recaptcha_invisible = new ReCaptchaBuilderInvisible('api_site_key', 'api_secret_key');
89
-		$this->recaptcha_v2 = new ReCaptchaBuilderV2('api_site_key', 'api_secret_key');
88
+        $this->recaptcha_invisible = new ReCaptchaBuilderInvisible('api_site_key', 'api_secret_key');
89
+        $this->recaptcha_v2 = new ReCaptchaBuilderV2('api_site_key', 'api_secret_key');
90 90
 
91
-	}
91
+    }
92 92
 }
93 93
\ No newline at end of file
Please login to merge, or discard this patch.
config/recaptcha.php 1 patch
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -13,52 +13,52 @@
 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
-	 * IP addresses for which validation will be skipped
45
-	 *
46
-	 */
47
-	'skip_ip'                      => [],
42
+    /**
43
+     *
44
+     * IP addresses for which validation will be skipped
45
+     *
46
+     */
47
+    'skip_ip'                      => [],
48 48
 
49
-	/**
50
-	 *
51
-	 * Default route called to check the Google reCAPTCHA token
52
-	 * @since v3.2.0
53
-	 *
54
-	 */
55
-	'default_validation_route'     => env('RECAPTCHA_DEFAULT_VALIDATION_ROUTE', 'biscolab-recaptcha/validate'),
49
+    /**
50
+     *
51
+     * Default route called to check the Google reCAPTCHA token
52
+     * @since v3.2.0
53
+     *
54
+     */
55
+    'default_validation_route'     => env('RECAPTCHA_DEFAULT_VALIDATION_ROUTE', 'biscolab-recaptcha/validate'),
56 56
 
57
-	/**
58
-	 *
59
-	 * The name of the parameter used to send Google reCAPTCHA token to verify route
60
-	 * @since v3.2.0
61
-	 *
62
-	 */
63
-	'default_token_parameter_name' => env('RECAPTCHA_DEFAULT_TOKEN_PARAMETER_NAME', 'token')
57
+    /**
58
+     *
59
+     * The name of the parameter used to send Google reCAPTCHA token to verify route
60
+     * @since v3.2.0
61
+     *
62
+     */
63
+    'default_token_parameter_name' => env('RECAPTCHA_DEFAULT_TOKEN_PARAMETER_NAME', 'token')
64 64
 ];
65 65
\ No newline at end of file
Please login to merge, or discard this patch.
src/Facades/ReCaptcha.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -18,13 +18,13 @@
 block discarded – undo
18 18
  */
19 19
 class ReCaptcha extends Facade {
20 20
 
21
-	/**
22
-	 * Get the registered name of the component.
23
-	 *
24
-	 * @return string
25
-	 */
26
-	protected static function getFacadeAccessor() {
21
+    /**
22
+     * Get the registered name of the component.
23
+     *
24
+     * @return string
25
+     */
26
+    protected static function getFacadeAccessor() {
27 27
 
28
-		return 'recaptcha';
29
-	}
28
+        return 'recaptcha';
29
+    }
30 30
 }
Please login to merge, or discard this patch.
src/helpers.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -11,13 +11,13 @@  discard block
 block discarded – undo
11 11
 use Biscolab\ReCaptcha\Facades\ReCaptcha;
12 12
 
13 13
 if (!function_exists('recaptcha')) {
14
-	/**
15
-	 * @return Biscolab\ReCaptcha\ReCaptchaBuilder
16
-	 */
17
-	function recaptcha() {
14
+    /**
15
+     * @return Biscolab\ReCaptcha\ReCaptchaBuilder
16
+     */
17
+    function recaptcha() {
18 18
 
19
-		return app('recaptcha');
20
-	}
19
+        return app('recaptcha');
20
+    }
21 21
 }
22 22
 
23 23
 /**
@@ -29,15 +29,15 @@  discard block
 block discarded – undo
29 29
  */
30 30
 if (!function_exists('htmlScriptTagJsApi')) {
31 31
 
32
-	/**
33
-	 * @param string $formId
34
-	 *
35
-	 * @return string
36
-	 */
37
-	function htmlScriptTagJsApi($formId = ''): string {
32
+    /**
33
+     * @param string $formId
34
+     *
35
+     * @return string
36
+     */
37
+    function htmlScriptTagJsApi($formId = ''): string {
38 38
 
39
-		return ReCaptcha::htmlScriptTagJsApi($formId);
40
-	}
39
+        return ReCaptcha::htmlScriptTagJsApi($formId);
40
+    }
41 41
 }
42 42
 
43 43
 /**
@@ -49,15 +49,15 @@  discard block
 block discarded – undo
49 49
  */
50 50
 if (!function_exists('htmlScriptTagJsApiV3')) {
51 51
 
52
-	/**
53
-	 * @param array $config
54
-	 *
55
-	 * @return string
56
-	 */
57
-	function htmlScriptTagJsApiV3($config = []): string {
52
+    /**
53
+     * @param array $config
54
+     *
55
+     * @return string
56
+     */
57
+    function htmlScriptTagJsApiV3($config = []): string {
58 58
 
59
-		return ReCaptcha::htmlScriptTagJsApiV3($config);
60
-	}
59
+        return ReCaptcha::htmlScriptTagJsApiV3($config);
60
+    }
61 61
 }
62 62
 
63 63
 /**
@@ -71,15 +71,15 @@  discard block
 block discarded – undo
71 71
  */
72 72
 if (!function_exists('htmlFormButton')) {
73 73
 
74
-	/**
75
-	 * @param null|string $buttonInnerHTML
76
-	 *
77
-	 * @return string
78
-	 */
79
-	function htmlFormButton(?string $buttonInnerHTML = 'Submit'): string {
74
+    /**
75
+     * @param null|string $buttonInnerHTML
76
+     *
77
+     * @return string
78
+     */
79
+    function htmlFormButton(?string $buttonInnerHTML = 'Submit'): string {
80 80
 
81
-		return ReCaptcha::htmlFormButton($buttonInnerHTML);
82
-	}
81
+        return ReCaptcha::htmlFormButton($buttonInnerHTML);
82
+    }
83 83
 }
84 84
 
85 85
 /**
@@ -91,12 +91,12 @@  discard block
 block discarded – undo
91 91
  */
92 92
 if (!function_exists('htmlFormSnippet')) {
93 93
 
94
-	/**
95
-	 * @return string
96
-	 */
97
-	function htmlFormSnippet(): string {
94
+    /**
95
+     * @return string
96
+     */
97
+    function htmlFormSnippet(): string {
98 98
 
99
-		return ReCaptcha::htmlFormSnippet();
100
-	}
99
+        return ReCaptcha::htmlFormSnippet();
100
+    }
101 101
 }
102 102
 
Please login to merge, or discard this patch.
src/ReCaptchaBuilderV2.php 2 patches
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -16,25 +16,25 @@
 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
-	 */
25
-	public function __construct(string $api_site_key, string $api_secret_key) {
19
+    /**
20
+     * ReCaptchaBuilderV2 constructor.
21
+     *
22
+     * @param string $api_site_key
23
+     * @param string $api_secret_key
24
+     */
25
+    public function __construct(string $api_site_key, string $api_secret_key) {
26 26
 
27
-		parent::__construct($api_site_key, $api_secret_key, 'v2');
28
-	}
27
+        parent::__construct($api_site_key, $api_secret_key, 'v2');
28
+    }
29 29
 
30
-	/**
31
-	 * Write ReCAPTCHA HTML tag in your FORM
32
-	 * Insert before </form> tag
33
-	 * @return string
34
-	 */
35
-	public function htmlFormSnippet(): string {
30
+    /**
31
+     * Write ReCAPTCHA HTML tag in your FORM
32
+     * Insert before </form> tag
33
+     * @return string
34
+     */
35
+    public function htmlFormSnippet(): string {
36 36
 
37
-		return ($this->version == 'v2') ? '<div class="g-recaptcha" data-sitekey="' . $this->api_site_key . '"></div>' : '';
38
-	}
37
+        return ($this->version == 'v2') ? '<div class="g-recaptcha" data-sitekey="' . $this->api_site_key . '"></div>' : '';
38
+    }
39 39
 
40 40
 }
41 41
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@
 block discarded – undo
34 34
 	 */
35 35
 	public function htmlFormSnippet(): string {
36 36
 
37
-		return ($this->version == 'v2') ? '<div class="g-recaptcha" data-sitekey="' . $this->api_site_key . '"></div>' : '';
37
+		return ($this->version == 'v2') ? '<div class="g-recaptcha" data-sitekey="'.$this->api_site_key.'"></div>' : '';
38 38
 	}
39 39
 
40 40
 }
41 41
\ No newline at end of file
Please login to merge, or discard this patch.
src/ReCaptchaBuilderV3.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -16,15 +16,15 @@
 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
-	 */
25
-	public function __construct(string $api_site_key, string $api_secret_key) {
19
+    /**
20
+     * ReCaptchaBuilderV3 constructor.
21
+     *
22
+     * @param string $api_site_key
23
+     * @param string $api_secret_key
24
+     */
25
+    public function __construct(string $api_site_key, string $api_secret_key) {
26 26
 
27
-		parent::__construct($api_site_key, $api_secret_key, 'v3');
28
-	}
27
+        parent::__construct($api_site_key, $api_secret_key, 'v3');
28
+    }
29 29
 
30 30
 }
31 31
\ No newline at end of file
Please login to merge, or discard this patch.
src/ReCaptchaBuilderInvisible.php 2 patches
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -16,28 +16,28 @@
 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
-	 */
25
-	public function __construct(string $api_site_key, string $api_secret_key) {
19
+    /**
20
+     * ReCaptchaBuilderInvisible constructor.
21
+     *
22
+     * @param string $api_site_key
23
+     * @param string $api_secret_key
24
+     */
25
+    public function __construct(string $api_site_key, string $api_secret_key) {
26 26
 
27
-		parent::__construct($api_site_key, $api_secret_key, 'invisible');
28
-	}
27
+        parent::__construct($api_site_key, $api_secret_key, 'invisible');
28
+    }
29 29
 
30
-	/**
31
-	 * Write HTML <button> tag in your HTML code
32
-	 * Insert before </form> tag
33
-	 *
34
-	 * @param string $buttonInnerHTML
35
-	 *
36
-	 * @return string
37
-	 */
38
-	public function htmlFormButton($buttonInnerHTML = 'Submit'): string {
30
+    /**
31
+     * Write HTML <button> tag in your HTML code
32
+     * Insert before </form> tag
33
+     *
34
+     * @param string $buttonInnerHTML
35
+     *
36
+     * @return string
37
+     */
38
+    public function htmlFormButton($buttonInnerHTML = 'Submit'): string {
39 39
 
40
-		return ($this->version == 'invisible') ? '<button class="g-recaptcha" data-sitekey="' . $this->api_site_key . '" data-callback="biscolabLaravelReCaptcha">' . $buttonInnerHTML . '</button>' : '';
41
-	}
40
+        return ($this->version == 'invisible') ? '<button class="g-recaptcha" data-sitekey="' . $this->api_site_key . '" data-callback="biscolabLaravelReCaptcha">' . $buttonInnerHTML . '</button>' : '';
41
+    }
42 42
 
43 43
 }
44 44
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@
 block discarded – undo
37 37
 	 */
38 38
 	public function htmlFormButton($buttonInnerHTML = 'Submit'): string {
39 39
 
40
-		return ($this->version == 'invisible') ? '<button class="g-recaptcha" data-sitekey="' . $this->api_site_key . '" data-callback="biscolabLaravelReCaptcha">' . $buttonInnerHTML . '</button>' : '';
40
+		return ($this->version == 'invisible') ? '<button class="g-recaptcha" data-sitekey="'.$this->api_site_key.'" data-callback="biscolabLaravelReCaptcha">'.$buttonInnerHTML.'</button>' : '';
41 41
 	}
42 42
 
43 43
 }
44 44
\ No newline at end of file
Please login to merge, or discard this patch.
src/ReCaptchaBuilder.php 3 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 			}
151 151
 			$html .= '<script>
152 152
 		       function biscolabLaravelReCaptcha(token) {
153
-		         document.getElementById("' . $formId . '").submit();
153
+		         document.getElementById("' . $formId.'").submit();
154 154
 		       }
155 155
 		     </script>';
156 156
 		}
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
 				$js_callback_catch = ($js_callback_catch) ? "{$js_callback_catch}(err)" : '';
175 175
 
176 176
 				$validate_function = "
177
-                fetch('/" . config('recaptcha.default_validation_route', 'biscolab-recaptcha/validate') . "?" . config('recaptcha.default_token_parameter_name', 'token') . "=' + token, {
177
+                fetch('/" . config('recaptcha.default_validation_route', 'biscolab-recaptcha/validate')."?".config('recaptcha.default_token_parameter_name', 'token')."=' + token, {
178 178
                     headers: {
179 179
                         \"X-Requested-With\": \"XMLHttpRequest\",
180 180
                         \"X-CSRF-TOKEN\": csrfToken.content
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 			'response' => $response,
231 231
 		]);
232 232
 
233
-		$url = $this->api_url . '?' . $params;
233
+		$url = $this->api_url.'?'.$params;
234 234
 
235 235
 		if (function_exists('curl_version')) {
236 236
 			$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
@@ -153,8 +153,7 @@  discard block
 block discarded – undo
153 153
 		         document.getElementById("' . $formId . '").submit();
154 154
 		       }
155 155
 		     </script>';
156
-		}
157
-		elseif ($this->version == 'v3') {
156
+		} elseif ($this->version == 'v3') {
158 157
 
159 158
 			$action = array_get($configuration, 'action', 'homepage');
160 159
 
@@ -164,8 +163,7 @@  discard block
 block discarded – undo
164 163
 			if ($js_custom_validation) {
165 164
 
166 165
 				$validate_function = ($js_custom_validation) ? "{$js_custom_validation}(token);" : '';
167
-			}
168
-			else {
166
+			} else {
169 167
 
170 168
 				$js_then_callback = array_get($configuration, 'callback_then', '');
171 169
 				$js_callback_catch = array_get($configuration, 'callback_catch', '');
@@ -239,8 +237,7 @@  discard block
 block discarded – undo
239 237
 			curl_setopt($curl, CURLOPT_TIMEOUT, 1);
240 238
 			curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
241 239
 			$curl_response = curl_exec($curl);
242
-		}
243
-		else {
240
+		} else {
244 241
 			$curl_response = file_get_contents($url);
245 242
 		}
246 243
 		if (is_null($curl_response) || empty($curl_response)) {
Please login to merge, or discard this patch.
Indentation   +210 added lines, -210 removed lines patch added patch discarded remove patch
@@ -14,166 +14,166 @@  discard block
 block discarded – undo
14 14
 
15 15
 class ReCaptchaBuilder {
16 16
 
17
-	/**
18
-	 * The Site key
19
-	 * please visit https://developers.google.com/recaptcha/docs/start
20
-	 * @var string
21
-	 */
22
-	protected $api_site_key;
23
-
24
-	/**
25
-	 * The Secret key
26
-	 * please visit https://developers.google.com/recaptcha/docs/start
27
-	 * @var string
28
-	 */
29
-	protected $api_secret_key;
30
-
31
-	/**
32
-	 * The chosen ReCAPTCHA version
33
-	 * please visit https://developers.google.com/recaptcha/docs/start
34
-	 * @var string
35
-	 */
36
-	protected $version;
37
-
38
-	/**
39
-	 * Whether is true the ReCAPTCHA is inactive
40
-	 * @var boolean
41
-	 */
42
-	protected $skip_by_ip = false;
43
-
44
-	/**
45
-	 * The API request URI
46
-	 */
47
-	protected $api_url = 'https://www.google.com/recaptcha/api/siteverify';
48
-
49
-	public function __construct($api_site_key, $api_secret_key, $version = 'v2') {
50
-
51
-		$this->setApiSiteKey($api_site_key);
52
-		$this->setApiSecretKey($api_secret_key);
53
-		$this->setVersion($version);
54
-		$this->setSkipByIp($this->skipByIp());
55
-	}
56
-
57
-	/**
58
-	 * @param string $api_site_key
59
-	 *
60
-	 * @return ReCaptchaBuilder
61
-	 */
62
-	public function setApiSiteKey(string $api_site_key): ReCaptchaBuilder {
63
-
64
-		$this->api_site_key = $api_site_key;
65
-
66
-		return $this;
67
-	}
68
-
69
-	/**
70
-	 * @param string $api_secret_key
71
-	 *
72
-	 * @return ReCaptchaBuilder
73
-	 */
74
-	public function setApiSecretKey(string $api_secret_key): ReCaptchaBuilder {
75
-
76
-		$this->api_secret_key = $api_secret_key;
77
-
78
-		return $this;
79
-	}
80
-
81
-	/**
82
-	 * @param string $version
83
-	 *
84
-	 * @return ReCaptchaBuilder
85
-	 */
86
-	public function setVersion(string $version): ReCaptchaBuilder {
87
-
88
-		$this->version = $version;
89
-
90
-		return $this;
91
-	}
92
-
93
-	/**
94
-	 * @return string
95
-	 */
96
-	public function getVersion(): string {
97
-
98
-		return $this->version;
99
-	}
100
-
101
-	/**
102
-	 * @param bool $skip_by_ip
103
-	 *
104
-	 * @return ReCaptchaBuilder
105
-	 */
106
-	public function setSkipByIp(bool $skip_by_ip): ReCaptchaBuilder {
107
-
108
-		$this->skip_by_ip = $skip_by_ip;
109
-
110
-		return $this;
111
-	}
112
-
113
-	/**
114
-	 * Checks whether the user IP address is among IPs "to be skipped"
115
-	 *
116
-	 * @return boolean
117
-	 */
118
-	public function skipByIp(): bool {
119
-
120
-		return (in_array(request()->ip(), config('recaptcha.skip_ip', [])));
121
-	}
122
-
123
-	/**
124
-	 * Write script HTML tag in you HTML code
125
-	 * Insert before </head> tag
126
-	 *
127
-	 * @param string|null $formId
128
-	 * @param array|null  $configuration
129
-	 *
130
-	 * @return string
131
-	 * @throws Exception
132
-	 */
133
-	public function htmlScriptTagJsApi(?string $formId = '', ?array $configuration = []): string {
134
-
135
-		if ($this->skip_by_ip) {
136
-			return '';
137
-		}
138
-
139
-		switch ($this->version) {
140
-			case 'v3':
141
-				$html = "<script src=\"https://www.google.com/recaptcha/api.js?render={$this->api_site_key}\"></script>";
142
-				break;
143
-			default:
144
-				$html = "<script src=\"https://www.google.com/recaptcha/api.js\" async defer></script>";
145
-		}
146
-
147
-		if ($this->version == 'invisible') {
148
-			if (!$formId) {
149
-				throw new Exception("formId required", 1);
150
-			}
151
-			$html .= '<script>
17
+    /**
18
+     * The Site key
19
+     * please visit https://developers.google.com/recaptcha/docs/start
20
+     * @var string
21
+     */
22
+    protected $api_site_key;
23
+
24
+    /**
25
+     * The Secret key
26
+     * please visit https://developers.google.com/recaptcha/docs/start
27
+     * @var string
28
+     */
29
+    protected $api_secret_key;
30
+
31
+    /**
32
+     * The chosen ReCAPTCHA version
33
+     * please visit https://developers.google.com/recaptcha/docs/start
34
+     * @var string
35
+     */
36
+    protected $version;
37
+
38
+    /**
39
+     * Whether is true the ReCAPTCHA is inactive
40
+     * @var boolean
41
+     */
42
+    protected $skip_by_ip = false;
43
+
44
+    /**
45
+     * The API request URI
46
+     */
47
+    protected $api_url = 'https://www.google.com/recaptcha/api/siteverify';
48
+
49
+    public function __construct($api_site_key, $api_secret_key, $version = 'v2') {
50
+
51
+        $this->setApiSiteKey($api_site_key);
52
+        $this->setApiSecretKey($api_secret_key);
53
+        $this->setVersion($version);
54
+        $this->setSkipByIp($this->skipByIp());
55
+    }
56
+
57
+    /**
58
+     * @param string $api_site_key
59
+     *
60
+     * @return ReCaptchaBuilder
61
+     */
62
+    public function setApiSiteKey(string $api_site_key): ReCaptchaBuilder {
63
+
64
+        $this->api_site_key = $api_site_key;
65
+
66
+        return $this;
67
+    }
68
+
69
+    /**
70
+     * @param string $api_secret_key
71
+     *
72
+     * @return ReCaptchaBuilder
73
+     */
74
+    public function setApiSecretKey(string $api_secret_key): ReCaptchaBuilder {
75
+
76
+        $this->api_secret_key = $api_secret_key;
77
+
78
+        return $this;
79
+    }
80
+
81
+    /**
82
+     * @param string $version
83
+     *
84
+     * @return ReCaptchaBuilder
85
+     */
86
+    public function setVersion(string $version): ReCaptchaBuilder {
87
+
88
+        $this->version = $version;
89
+
90
+        return $this;
91
+    }
92
+
93
+    /**
94
+     * @return string
95
+     */
96
+    public function getVersion(): string {
97
+
98
+        return $this->version;
99
+    }
100
+
101
+    /**
102
+     * @param bool $skip_by_ip
103
+     *
104
+     * @return ReCaptchaBuilder
105
+     */
106
+    public function setSkipByIp(bool $skip_by_ip): ReCaptchaBuilder {
107
+
108
+        $this->skip_by_ip = $skip_by_ip;
109
+
110
+        return $this;
111
+    }
112
+
113
+    /**
114
+     * Checks whether the user IP address is among IPs "to be skipped"
115
+     *
116
+     * @return boolean
117
+     */
118
+    public function skipByIp(): bool {
119
+
120
+        return (in_array(request()->ip(), config('recaptcha.skip_ip', [])));
121
+    }
122
+
123
+    /**
124
+     * Write script HTML tag in you HTML code
125
+     * Insert before </head> tag
126
+     *
127
+     * @param string|null $formId
128
+     * @param array|null  $configuration
129
+     *
130
+     * @return string
131
+     * @throws Exception
132
+     */
133
+    public function htmlScriptTagJsApi(?string $formId = '', ?array $configuration = []): string {
134
+
135
+        if ($this->skip_by_ip) {
136
+            return '';
137
+        }
138
+
139
+        switch ($this->version) {
140
+            case 'v3':
141
+                $html = "<script src=\"https://www.google.com/recaptcha/api.js?render={$this->api_site_key}\"></script>";
142
+                break;
143
+            default:
144
+                $html = "<script src=\"https://www.google.com/recaptcha/api.js\" async defer></script>";
145
+        }
146
+
147
+        if ($this->version == 'invisible') {
148
+            if (!$formId) {
149
+                throw new Exception("formId required", 1);
150
+            }
151
+            $html .= '<script>
152 152
 		       function biscolabLaravelReCaptcha(token) {
153 153
 		         document.getElementById("' . $formId . '").submit();
154 154
 		       }
155 155
 		     </script>';
156
-		}
157
-		elseif ($this->version == 'v3') {
156
+        }
157
+        elseif ($this->version == 'v3') {
158 158
 
159
-			$action = array_get($configuration, 'action', 'homepage');
159
+            $action = array_get($configuration, 'action', 'homepage');
160 160
 
161
-			$js_custom_validation = array_get($configuration, 'custom_validation', '');
161
+            $js_custom_validation = array_get($configuration, 'custom_validation', '');
162 162
 
163
-			// Check if set custom_validation. That function will override default fetch validation function
164
-			if ($js_custom_validation) {
163
+            // Check if set custom_validation. That function will override default fetch validation function
164
+            if ($js_custom_validation) {
165 165
 
166
-				$validate_function = ($js_custom_validation) ? "{$js_custom_validation}(token);" : '';
167
-			}
168
-			else {
166
+                $validate_function = ($js_custom_validation) ? "{$js_custom_validation}(token);" : '';
167
+            }
168
+            else {
169 169
 
170
-				$js_then_callback = array_get($configuration, 'callback_then', '');
171
-				$js_callback_catch = array_get($configuration, 'callback_catch', '');
170
+                $js_then_callback = array_get($configuration, 'callback_then', '');
171
+                $js_callback_catch = array_get($configuration, 'callback_catch', '');
172 172
 
173
-				$js_then_callback = ($js_then_callback) ? "{$js_then_callback}(response)" : '';
174
-				$js_callback_catch = ($js_callback_catch) ? "{$js_callback_catch}(err)" : '';
173
+                $js_then_callback = ($js_then_callback) ? "{$js_then_callback}(response)" : '';
174
+                $js_callback_catch = ($js_callback_catch) ? "{$js_callback_catch}(err)" : '';
175 175
 
176
-				$validate_function = "
176
+                $validate_function = "
177 177
                 fetch('/" . config('recaptcha.default_validation_route', 'biscolab-recaptcha/validate') . "?" . config('recaptcha.default_token_parameter_name', 'token') . "=' + token, {
178 178
                     headers: {
179 179
                         \"X-Requested-With\": \"XMLHttpRequest\",
@@ -186,9 +186,9 @@  discard block
 block discarded – undo
186 186
                 .catch(function(err) {
187 187
                     {$js_callback_catch}
188 188
                 });";
189
-			}
189
+            }
190 190
 
191
-			$html .= "<script>
191
+            $html .= "<script>
192 192
                     var csrfToken = document.head.querySelector('meta[name=\"csrf-token\"]');
193 193
                   grecaptcha.ready(function() {
194 194
                       grecaptcha.execute('{$this->api_site_key}', {action: '{$action}'}).then(function(token) {
@@ -196,63 +196,63 @@  discard block
 block discarded – undo
196 196
                       });
197 197
                   });
198 198
 		     </script>";
199
-		}
200
-
201
-		return $html;
202
-	}
203
-
204
-	/**
205
-	 * @param array|null $configuration
206
-	 *
207
-	 * @return string
208
-	 */
209
-	public function htmlScriptTagJsApiV3(?array $configuration = []): string {
210
-
211
-		return $this->htmlScriptTagJsApi('', $configuration);
212
-	}
213
-
214
-	/**
215
-	 * Call out to reCAPTCHA and process the response
216
-	 *
217
-	 * @param string $response
218
-	 *
219
-	 * @return boolean|array
220
-	 */
221
-	public function validate($response) {
222
-
223
-		if ($this->skip_by_ip) {
224
-			return true;
225
-		}
226
-
227
-		$params = http_build_query([
228
-			'secret'   => $this->api_secret_key,
229
-			'remoteip' => request()->getClientIp(),
230
-			'response' => $response,
231
-		]);
232
-
233
-		$url = $this->api_url . '?' . $params;
234
-
235
-		if (function_exists('curl_version')) {
236
-			$curl = curl_init($url);
237
-			curl_setopt($curl, CURLOPT_HEADER, false);
238
-			curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
239
-			curl_setopt($curl, CURLOPT_TIMEOUT, 1);
240
-			curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
241
-			$curl_response = curl_exec($curl);
242
-		}
243
-		else {
244
-			$curl_response = file_get_contents($url);
245
-		}
246
-		if (is_null($curl_response) || empty($curl_response)) {
247
-			return false;
248
-		}
249
-		$response = json_decode(trim($curl_response), true);
250
-
251
-		if ($this->version == 'v3') {
252
-			return $response;
253
-		}
254
-
255
-		return $response['success'];
256
-
257
-	}
199
+        }
200
+
201
+        return $html;
202
+    }
203
+
204
+    /**
205
+     * @param array|null $configuration
206
+     *
207
+     * @return string
208
+     */
209
+    public function htmlScriptTagJsApiV3(?array $configuration = []): string {
210
+
211
+        return $this->htmlScriptTagJsApi('', $configuration);
212
+    }
213
+
214
+    /**
215
+     * Call out to reCAPTCHA and process the response
216
+     *
217
+     * @param string $response
218
+     *
219
+     * @return boolean|array
220
+     */
221
+    public function validate($response) {
222
+
223
+        if ($this->skip_by_ip) {
224
+            return true;
225
+        }
226
+
227
+        $params = http_build_query([
228
+            'secret'   => $this->api_secret_key,
229
+            'remoteip' => request()->getClientIp(),
230
+            'response' => $response,
231
+        ]);
232
+
233
+        $url = $this->api_url . '?' . $params;
234
+
235
+        if (function_exists('curl_version')) {
236
+            $curl = curl_init($url);
237
+            curl_setopt($curl, CURLOPT_HEADER, false);
238
+            curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
239
+            curl_setopt($curl, CURLOPT_TIMEOUT, 1);
240
+            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
241
+            $curl_response = curl_exec($curl);
242
+        }
243
+        else {
244
+            $curl_response = file_get_contents($url);
245
+        }
246
+        if (is_null($curl_response) || empty($curl_response)) {
247
+            return false;
248
+        }
249
+        $response = json_decode(trim($curl_response), true);
250
+
251
+        if ($this->version == 'v3') {
252
+            return $response;
253
+        }
254
+
255
+        return $response['success'];
256
+
257
+    }
258 258
 }
259 259
\ No newline at end of file
Please login to merge, or discard this patch.