Skip to content
This repository was archived by the owner on Jun 10, 2024. It is now read-only.

Commit f0a827b

Browse files
committed
Code restyling and optimization (PSR2)
1 parent 931aef4 commit f0a827b

9 files changed

+83
-46
lines changed

.scrutinizer.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ build:
77
coverage:
88
file: clover.xml
99
format: clover
10+
tools:
11+
php_code_sniffer:
12+
config:
13+
standard: PSR2

src/Controllers/ReCaptchaController.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@
1616
* Class ReCaptchaController
1717
* @package Biscolab\ReCaptcha\Controllers
1818
*/
19-
class ReCaptchaController extends Controller {
19+
class ReCaptchaController extends Controller
20+
{
2021

2122
/**
2223
* @return array
2324
*/
24-
public function validateV3(): array {
25+
public function validateV3(): array
26+
{
2527

2628
$token = request()->input(config('recaptcha.default_token_parameter_name', 'token'), '');
29+
2730
return recaptcha()->validate($token);
2831
}
2932
}

src/Facades/ReCaptcha.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@
1616
* Class ReCaptcha
1717
* @package Biscolab\ReCaptcha\Facades
1818
*/
19-
class ReCaptcha extends Facade {
19+
class ReCaptcha extends Facade
20+
{
2021

2122
/**
2223
* Get the registered name of the component.
2324
*
2425
* @return string
2526
*/
26-
protected static function getFacadeAccessor() {
27+
protected static function getFacadeAccessor()
28+
{
2729

2830
return 'recaptcha';
2931
}

src/ReCaptchaBuilder.php

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
* Class ReCaptchaBuilder
1818
* @package Biscolab\ReCaptcha
1919
*/
20-
class ReCaptchaBuilder {
20+
class ReCaptchaBuilder
21+
{
2122

2223
/**
2324
* @var string
@@ -85,7 +86,8 @@ public function __construct(
8586
*
8687
* @return ReCaptchaBuilder
8788
*/
88-
public function setApiSiteKey(string $api_site_key): ReCaptchaBuilder {
89+
public function setApiSiteKey(string $api_site_key): ReCaptchaBuilder
90+
{
8991

9092
$this->api_site_key = $api_site_key;
9193

@@ -97,7 +99,8 @@ public function setApiSiteKey(string $api_site_key): ReCaptchaBuilder {
9799
*
98100
* @return ReCaptchaBuilder
99101
*/
100-
public function setApiSecretKey(string $api_secret_key): ReCaptchaBuilder {
102+
public function setApiSecretKey(string $api_secret_key): ReCaptchaBuilder
103+
{
101104

102105
$this->api_secret_key = $api_secret_key;
103106

@@ -107,7 +110,8 @@ public function setApiSecretKey(string $api_secret_key): ReCaptchaBuilder {
107110
/**
108111
* @return int
109112
*/
110-
public function getCurlTimeout(): int {
113+
public function getCurlTimeout(): int
114+
{
111115

112116
return config('recaptcha.curl_timeout', self::DEFAULT_CURL_TIMEOUT);
113117
}
@@ -117,7 +121,8 @@ public function getCurlTimeout(): int {
117121
*
118122
* @return ReCaptchaBuilder
119123
*/
120-
public function setVersion(string $version): ReCaptchaBuilder {
124+
public function setVersion(string $version): ReCaptchaBuilder
125+
{
121126

122127
$this->version = $version;
123128

@@ -127,7 +132,8 @@ public function setVersion(string $version): ReCaptchaBuilder {
127132
/**
128133
* @return string
129134
*/
130-
public function getVersion(): string {
135+
public function getVersion(): string
136+
{
131137

132138
return $this->version;
133139
}
@@ -137,7 +143,8 @@ public function getVersion(): string {
137143
*
138144
* @return ReCaptchaBuilder
139145
*/
140-
public function setSkipByIp(bool $skip_by_ip): ReCaptchaBuilder {
146+
public function setSkipByIp(bool $skip_by_ip): ReCaptchaBuilder
147+
{
141148

142149
$this->skip_by_ip = $skip_by_ip;
143150

@@ -147,7 +154,8 @@ public function setSkipByIp(bool $skip_by_ip): ReCaptchaBuilder {
147154
/**
148155
* @return array|mixed
149156
*/
150-
public function getIpWhitelist() {
157+
public function getIpWhitelist()
158+
{
151159

152160
$whitelist = config('recaptcha.skip_ip', []);
153161

@@ -163,7 +171,8 @@ public function getIpWhitelist() {
163171
*
164172
* @return boolean
165173
*/
166-
public function skipByIp(): bool {
174+
public function skipByIp(): bool
175+
{
167176

168177
return (in_array(request()->ip(), $this->getIpWhitelist()));
169178
}
@@ -178,7 +187,8 @@ public function skipByIp(): bool {
178187
* @return string
179188
* @throws Exception
180189
*/
181-
public function htmlScriptTagJsApi(?string $formId = '', ?array $configuration = []): string {
190+
public function htmlScriptTagJsApi(?string $formId = '', ?array $configuration = []): string
191+
{
182192

183193
if ($this->skip_by_ip) {
184194
return '';
@@ -203,8 +213,7 @@ function biscolabLaravelReCaptcha(token) {
203213
document.getElementById("' . $formId . '").submit();
204214
}
205215
</script>';
206-
}
207-
elseif ($this->version == 'v3') {
216+
} elseif ($this->version == 'v3') {
208217

209218
$action = Arr::get($configuration, 'action', 'homepage');
210219

@@ -214,8 +223,7 @@ function biscolabLaravelReCaptcha(token) {
214223
if ($js_custom_validation) {
215224

216225
$validate_function = ($js_custom_validation) ? "{$js_custom_validation}(token);" : '';
217-
}
218-
else {
226+
} else {
219227

220228
$js_then_callback = Arr::get($configuration, 'callback_then', '');
221229
$js_callback_catch = Arr::get($configuration, 'callback_catch', '');
@@ -258,7 +266,8 @@ function biscolabLaravelReCaptcha(token) {
258266
*
259267
* @return string
260268
*/
261-
public function htmlScriptTagJsApiV3(?array $configuration = []): string {
269+
public function htmlScriptTagJsApiV3(?array $configuration = []): string
270+
{
262271

263272
return $this->htmlScriptTagJsApi('', $configuration);
264273
}
@@ -270,7 +279,8 @@ public function htmlScriptTagJsApiV3(?array $configuration = []): string {
270279
*
271280
* @return boolean|array
272281
*/
273-
public function validate($response) {
282+
public function validate($response)
283+
{
274284

275285
if ($this->skip_by_ip) {
276286
if ($this->returnArray()) {
@@ -294,14 +304,14 @@ public function validate($response) {
294304
$url = $this->api_url . '?' . $params;
295305

296306
if (function_exists('curl_version')) {
307+
297308
$curl = curl_init($url);
298309
curl_setopt($curl, CURLOPT_HEADER, false);
299310
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
300311
curl_setopt($curl, CURLOPT_TIMEOUT, $this->getCurlTimeout());
301312
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
302313
$curl_response = curl_exec($curl);
303-
}
304-
else {
314+
} else {
305315
$curl_response = file_get_contents($url);
306316
}
307317

@@ -348,7 +358,8 @@ public function getApiSecretKey(): string
348358
/**
349359
* @return bool
350360
*/
351-
protected function returnArray(): bool {
361+
protected function returnArray(): bool
362+
{
352363

353364
return ($this->version == 'v3');
354365
}

src/ReCaptchaBuilderInvisible.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@
1414
* Class ReCaptchaBuilderInvisible
1515
* @package Biscolab\ReCaptcha
1616
*/
17-
class ReCaptchaBuilderInvisible extends ReCaptchaBuilder {
17+
class ReCaptchaBuilderInvisible extends ReCaptchaBuilder
18+
{
1819

1920
/**
2021
* ReCaptchaBuilderInvisible constructor.
2122
*
22-
* @param string $api_site_key
23-
* @param string $api_secret_key
23+
* @param string $api_site_key
24+
* @param string $api_secret_key
2425
*/
2526
public function __construct(string $api_site_key, string $api_secret_key)
2627
{
@@ -36,7 +37,8 @@ public function __construct(string $api_site_key, string $api_secret_key)
3637
*
3738
* @return string
3839
*/
39-
public function htmlFormButton($buttonInnerHTML = 'Submit'): string {
40+
public function htmlFormButton($buttonInnerHTML = 'Submit'): string
41+
{
4042

4143
return ($this->version == 'invisible') ? '<button class="g-recaptcha" data-sitekey="' . $this->api_site_key . '" data-callback="biscolabLaravelReCaptcha">' . $buttonInnerHTML . '</button>' : '';
4244
}

src/ReCaptchaBuilderV2.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@
1414
* Class ReCaptchaBuilderV2
1515
* @package Biscolab\ReCaptcha
1616
*/
17-
class ReCaptchaBuilderV2 extends ReCaptchaBuilder {
17+
class ReCaptchaBuilderV2 extends ReCaptchaBuilder
18+
{
1819

1920
/**
2021
* ReCaptchaBuilderV2 constructor.
2122
*
22-
* @param string $api_site_key
23-
* @param string $api_secret_key
23+
* @param string $api_site_key
24+
* @param string $api_secret_key
2425
*/
2526
public function __construct(string $api_site_key, string $api_secret_key)
2627
{
@@ -33,7 +34,8 @@ public function __construct(string $api_site_key, string $api_secret_key)
3334
* Insert before </form> tag
3435
* @return string
3536
*/
36-
public function htmlFormSnippet(): string {
37+
public function htmlFormSnippet(): string
38+
{
3739

3840
return ($this->version == 'v2') ? '<div class="g-recaptcha" data-sitekey="' . $this->api_site_key . '"></div>' : '';
3941
}

src/ReCaptchaBuilderV3.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@
1414
* Class ReCaptchaBuilderV3
1515
* @package Biscolab\ReCaptcha
1616
*/
17-
class ReCaptchaBuilderV3 extends ReCaptchaBuilder {
17+
class ReCaptchaBuilderV3 extends ReCaptchaBuilder
18+
{
1819

1920
/**
2021
* ReCaptchaBuilderV3 constructor.
2122
*
22-
* @param string $api_site_key
23-
* @param string $api_secret_key
23+
* @param string $api_site_key
24+
* @param string $api_secret_key
2425
*/
2526
public function __construct(string $api_site_key, string $api_secret_key)
2627
{

src/ReCaptchaServiceProvider.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
* Class ReCaptchaServiceProvider
1919
* @package Biscolab\ReCaptcha
2020
*/
21-
class ReCaptchaServiceProvider extends ServiceProvider {
21+
class ReCaptchaServiceProvider extends ServiceProvider
22+
{
2223

2324
/**
2425
* Indicates if loading of the provider is deferred.
@@ -30,7 +31,8 @@ class ReCaptchaServiceProvider extends ServiceProvider {
3031
/**
3132
*
3233
*/
33-
public function boot() {
34+
public function boot()
35+
{
3436

3537
$this->addValidationRule();
3638
// $this->loadRoutesFrom(__DIR__ . '/routes/routes.php');
@@ -44,7 +46,8 @@ public function boot() {
4446
/**
4547
* Extends Validator to include a recaptcha type
4648
*/
47-
public function addValidationRule() {
49+
public function addValidationRule()
50+
{
4851

4952
Validator::extendImplicit('recaptcha', function ($attribute, $value, $parameters, $validator) {
5053

@@ -57,7 +60,8 @@ public function addValidationRule() {
5760
*
5861
* @return void
5962
*/
60-
public function register() {
63+
public function register()
64+
{
6165

6266
$this->mergeConfigFrom(
6367
__DIR__ . '/../config/recaptcha.php', 'recaptcha'
@@ -71,7 +75,8 @@ public function register() {
7175
*
7276
* @return array
7377
*/
74-
public function provides(): array {
78+
public function provides(): array
79+
{
7580

7681
return ['recaptcha'];
7782
}
@@ -81,7 +86,8 @@ public function provides(): array {
8186
*
8287
* @since v3.4.1
8388
*/
84-
protected function registerRoutes(): ReCaptchaServiceProvider {
89+
protected function registerRoutes(): ReCaptchaServiceProvider
90+
{
8591

8692
Route::get(
8793
config('recaptcha.default_validation_route', 'biscolab-recaptcha/validate'),
@@ -96,7 +102,8 @@ protected function registerRoutes(): ReCaptchaServiceProvider {
96102
*
97103
* @return void
98104
*/
99-
protected function registerReCaptchaBuilder() {
105+
protected function registerReCaptchaBuilder()
106+
{
100107

101108
$this->app->singleton('recaptcha', function ($app) {
102109

0 commit comments

Comments
 (0)