From a43a749d77c5d50c5a858917637f0b97db00efe5 Mon Sep 17 00:00:00 2001 From: Italo Date: Wed, 6 Mar 2024 17:04:40 +0000 Subject: [PATCH] Apply fixes from StyleCI [ci skip] [skip ci] --- config/recaptcha.php | 12 +++---- lang/en/validation.php | 4 +-- .../Controllers/ConfirmationController.php | 1 + src/Http/Middleware/Builders/ReCaptcha.php | 1 + src/Http/Middleware/ConfirmReCaptcha.php | 1 + src/Http/Middleware/VerifyHelpers.php | 1 + src/Http/Middleware/VerifyReCaptchaV2.php | 2 ++ src/Http/Middleware/VerifyReCaptchaV3.php | 1 + src/Http/ReCaptchaResponse.php | 2 ++ src/Http/ValidatesResponse.php | 1 + src/ReCaptcha.php | 3 +- src/ReCaptchaFake.php | 2 ++ src/RequestMacro.php | 1 + tests/Http/Middleware/ScoreMiddlewareTest.php | 34 +++++++++---------- tests/Http/ReCaptchaResponseTest.php | 12 +++---- tests/ReCaptchaTest.php | 32 ++++++++--------- 16 files changed, 62 insertions(+), 48 deletions(-) diff --git a/config/recaptcha.php b/config/recaptcha.php index a51453e..acc1a6f 100644 --- a/config/recaptcha.php +++ b/config/recaptcha.php @@ -43,7 +43,7 @@ | */ - 'hostname' => env('RECAPTCHA_HOSTNAME'), + 'hostname' => env('RECAPTCHA_HOSTNAME'), 'apk_package_name' => env('RECAPTCHA_APK_PACKAGE_NAME'), /* @@ -73,7 +73,7 @@ 'remember' => [ 'enabled' => false, - 'key' => '_recaptcha', + 'key' => '_recaptcha', 'minutes' => 10, ], @@ -107,19 +107,19 @@ 'credentials' => [ ReCaptcha::CHECKBOX => [ 'secret' => env('RECAPTCHA_CHECKBOX_SECRET', ReCaptcha::TEST_V2_SECRET), - 'key' => env('RECAPTCHA_CHECKBOX_KEY', ReCaptcha::TEST_V2_KEY), + 'key' => env('RECAPTCHA_CHECKBOX_KEY', ReCaptcha::TEST_V2_KEY), ], ReCaptcha::INVISIBLE => [ 'secret' => env('RECAPTCHA_INVISIBLE_SECRET', ReCaptcha::TEST_V2_SECRET), - 'key' => env('RECAPTCHA_INVISIBLE_KEY', ReCaptcha::TEST_V2_KEY), + 'key' => env('RECAPTCHA_INVISIBLE_KEY', ReCaptcha::TEST_V2_KEY), ], ReCaptcha::ANDROID => [ 'secret' => env('RECAPTCHA_ANDROID_SECRET', ReCaptcha::TEST_V2_SECRET), - 'key' => env('RECAPTCHA_ANDROID_KEY', ReCaptcha::TEST_V2_KEY), + 'key' => env('RECAPTCHA_ANDROID_KEY', ReCaptcha::TEST_V2_KEY), ], ReCaptcha::SCORE => [ 'secret' => env('RECAPTCHA_SCORE_SECRET'), - 'key' => env('RECAPTCHA_SCORE_KEY'), + 'key' => env('RECAPTCHA_SCORE_KEY'), ], ], ]; diff --git a/lang/en/validation.php b/lang/en/validation.php index 0c73891..10bcaba 100644 --- a/lang/en/validation.php +++ b/lang/en/validation.php @@ -1,7 +1,7 @@ 'The reCAPTCHA challenge does not matches this action.', + 'match' => 'The reCAPTCHA challenge does not matches this action.', 'missing' => 'The reCAPTCHA challenge was not completed or is missing.', - 'error' => 'Error resolving the reCAPTCHA challenge: :errors.', + 'error' => 'Error resolving the reCAPTCHA challenge: :errors.', ]; diff --git a/src/Http/Controllers/ConfirmationController.php b/src/Http/Controllers/ConfirmationController.php index f9a16e4..7a0b1d1 100644 --- a/src/Http/Controllers/ConfirmationController.php +++ b/src/Http/Controllers/ConfirmationController.php @@ -6,6 +6,7 @@ use Illuminate\Http\Response; use Illuminate\Routing\Controller; use Laragear\ReCaptcha\Http\Middleware\Builders\ReCaptcha; + use function redirect; class ConfirmationController extends Controller diff --git a/src/Http/Middleware/Builders/ReCaptcha.php b/src/Http/Middleware/Builders/ReCaptcha.php index ba54c87..537aac7 100644 --- a/src/Http/Middleware/Builders/ReCaptcha.php +++ b/src/Http/Middleware/Builders/ReCaptcha.php @@ -8,6 +8,7 @@ use Laragear\ReCaptcha\Http\Middleware\VerifyReCaptchaV3; use Laragear\ReCaptcha\ReCaptcha as BaseReCaptcha; use LogicException; + use function config; use function debug_backtrace; use function max; diff --git a/src/Http/Middleware/ConfirmReCaptcha.php b/src/Http/Middleware/ConfirmReCaptcha.php index 4057fa7..8eaad66 100644 --- a/src/Http/Middleware/ConfirmReCaptcha.php +++ b/src/Http/Middleware/ConfirmReCaptcha.php @@ -5,6 +5,7 @@ use Closure; use Illuminate\Contracts\Config\Repository as ConfigContract; use Illuminate\Http\Request; + use function redirect; use function url; diff --git a/src/Http/Middleware/VerifyHelpers.php b/src/Http/Middleware/VerifyHelpers.php index 45fcc82..f3b1bb3 100644 --- a/src/Http/Middleware/VerifyHelpers.php +++ b/src/Http/Middleware/VerifyHelpers.php @@ -7,6 +7,7 @@ use Laragear\ReCaptcha\Facades\ReCaptcha as ReCaptchaFacade; use Laragear\ReCaptcha\Http\ReCaptchaResponse; use Laragear\ReCaptcha\ReCaptcha; + use function app; use function back; use function strtolower; diff --git a/src/Http/Middleware/VerifyReCaptchaV2.php b/src/Http/Middleware/VerifyReCaptchaV2.php index 77e44c8..6124341 100644 --- a/src/Http/Middleware/VerifyReCaptchaV2.php +++ b/src/Http/Middleware/VerifyReCaptchaV2.php @@ -7,9 +7,11 @@ use Illuminate\Http\Request; use Laragear\ReCaptcha\ReCaptcha; use LogicException; + use function now; use function session; use function strtolower; + use const INF; class VerifyReCaptchaV2 diff --git a/src/Http/Middleware/VerifyReCaptchaV3.php b/src/Http/Middleware/VerifyReCaptchaV3.php index 241cf2f..b589da8 100644 --- a/src/Http/Middleware/VerifyReCaptchaV3.php +++ b/src/Http/Middleware/VerifyReCaptchaV3.php @@ -8,6 +8,7 @@ use Laragear\ReCaptcha\Facades\ReCaptcha as ReCaptchaFacade; use Laragear\ReCaptcha\Http\ReCaptchaResponse; use Laragear\ReCaptcha\ReCaptcha; + use function app; class VerifyReCaptchaV3 diff --git a/src/Http/ReCaptchaResponse.php b/src/Http/ReCaptchaResponse.php index ceea57c..8cdf275 100644 --- a/src/Http/ReCaptchaResponse.php +++ b/src/Http/ReCaptchaResponse.php @@ -8,9 +8,11 @@ use Illuminate\Http\Client\Response; use Illuminate\Support\Carbon; use JsonSerializable; + use function array_key_exists; use function json_encode; use function value; + use const JSON_THROW_ON_ERROR; /** diff --git a/src/Http/ValidatesResponse.php b/src/Http/ValidatesResponse.php index f6e3549..f346887 100644 --- a/src/Http/ValidatesResponse.php +++ b/src/Http/ValidatesResponse.php @@ -4,6 +4,7 @@ use Illuminate\Support\Arr; use Illuminate\Validation\ValidationException; + use function array_filter; use function back; use function config; diff --git a/src/ReCaptcha.php b/src/ReCaptcha.php index 862672d..e899ee0 100644 --- a/src/ReCaptcha.php +++ b/src/ReCaptcha.php @@ -7,6 +7,7 @@ use Illuminate\Http\Client\Factory; use Laragear\ReCaptcha\Http\ReCaptchaResponse; use LogicException; + use function app; class ReCaptcha @@ -87,7 +88,7 @@ protected function request(string $challenge, string $ip, string $version): Prom ->async() ->withOptions($this->config->get('recaptcha.client')) ->post(static::SERVER_ENDPOINT, [ - 'secret' => $this->secret($version), + 'secret' => $this->secret($version), 'response' => $challenge, 'remoteip' => $ip, ]); diff --git a/src/ReCaptchaFake.php b/src/ReCaptchaFake.php index 7e7fefb..0e57646 100644 --- a/src/ReCaptchaFake.php +++ b/src/ReCaptchaFake.php @@ -8,8 +8,10 @@ use GuzzleHttp\Psr7\Response as GuzzleResponse; use Illuminate\Http\Client\Response; use Laragear\ReCaptcha\Http\ReCaptchaResponse; + use function json_encode; use function now; + use const JSON_THROW_ON_ERROR; /** diff --git a/src/RequestMacro.php b/src/RequestMacro.php index 66024ac..728bc87 100644 --- a/src/RequestMacro.php +++ b/src/RequestMacro.php @@ -3,6 +3,7 @@ namespace Laragear\ReCaptcha; use Laragear\ReCaptcha\Http\ReCaptchaResponse; + use function app; /** diff --git a/tests/Http/Middleware/ScoreMiddlewareTest.php b/tests/Http/Middleware/ScoreMiddlewareTest.php index e213e15..dd48d77 100644 --- a/tests/Http/Middleware/ScoreMiddlewareTest.php +++ b/tests/Http/Middleware/ScoreMiddlewareTest.php @@ -39,12 +39,12 @@ public function test_local_fakes_human_response_automatically(): void ->assertOk() ->assertExactJson( [ - 'success' => true, - 'score' => 1, - 'action' => null, - 'hostname' => null, + 'success' => true, + 'score' => 1, + 'action' => null, + 'hostname' => null, 'apk_package_name' => null, - 'challenge_ts' => now()->toAtomString(), + 'challenge_ts' => now()->toAtomString(), ] ); } @@ -60,12 +60,12 @@ public function test_local_fakes_robot_response_if_input_is_robot_present(): voi ->assertOk() ->assertExactJson( [ - 'success' => true, - 'score' => 0, - 'action' => null, - 'hostname' => null, + 'success' => true, + 'score' => 0, + 'action' => null, + 'hostname' => null, 'apk_package_name' => null, - 'challenge_ts' => now()->toAtomString(), + 'challenge_ts' => now()->toAtomString(), ] ); } @@ -104,7 +104,7 @@ public function test_faking_on_production_will_fake_the_response_anyway(): void ->assertOk() ->assertJsonFragment([ 'success' => true, - 'score' => 1.0, + 'score' => 1.0, ]); static::assertInstanceOf(ReCaptchaFake::class, $this->app->make(ReCaptcha::class)); @@ -118,8 +118,8 @@ public function test_validates_if_real(): void ->andReturn( $this->fulfilledResponse([ 'success' => true, - 'score' => 0.5, - 'foo' => 'bar', + 'score' => 0.5, + 'foo' => 'bar', ]) ); @@ -127,8 +127,8 @@ public function test_validates_if_real(): void ->assertOk() ->assertExactJson([ 'success' => true, - 'score' => 0.5, - 'foo' => 'bar', + 'score' => 0.5, + 'foo' => 'bar', ]); } @@ -437,7 +437,7 @@ public function test_checks_for_human_score(): void ->with( ReCaptcha::SERVER_ENDPOINT, [ - 'secret' => 'secret', + 'secret' => 'secret', 'response' => 'token', 'remoteip' => '127.0.0.1', ] @@ -446,7 +446,7 @@ public function test_checks_for_human_score(): void ->andReturn( $this->fulfilledPromise([ 'success' => true, - 'score' => 0.5, + 'score' => 0.5, ]) ); diff --git a/tests/Http/ReCaptchaResponseTest.php b/tests/Http/ReCaptchaResponseTest.php index d3d9287..3a18eba 100644 --- a/tests/Http/ReCaptchaResponseTest.php +++ b/tests/Http/ReCaptchaResponseTest.php @@ -65,7 +65,7 @@ public function test_checks_resolve(): void new Response( new GuzzleResponse(200, ['Content-type' => 'application/json'], json_encode([ 'success' => true, - 'foo' => 'bar', + 'foo' => 'bar', ], JSON_THROW_ON_ERROR)) ) ); @@ -80,7 +80,7 @@ public function test_always_returns_human_if_not_score_response(): void { $response = $this->fulfilledResponse([ 'success' => true, - 'foo' => 'bar', + 'foo' => 'bar', ]); static::assertTrue($response->isHuman()); @@ -90,8 +90,8 @@ public function test_always_returns_human_if_not_score_response(): void public function test_returns_carbon_of_challenge_ts(): void { $response = $this->fulfilledResponse([ - 'success' => true, - 'foo' => 'bar', + 'success' => true, + 'foo' => 'bar', 'challenge_ts' => ($now = now())->toIso8601ZuluString(), ]); @@ -127,8 +127,8 @@ public function test_validation_fails_if_no_success(): void $response = $this->fulfilledResponse([ 'success' => false, - 'foo' => 'bar', - 'errors' => ['quz', 'cougar'], + 'foo' => 'bar', + 'errors' => ['quz', 'cougar'], ]); try { diff --git a/tests/ReCaptchaTest.php b/tests/ReCaptchaTest.php index 37b0ccc..bbd7b50 100644 --- a/tests/ReCaptchaTest.php +++ b/tests/ReCaptchaTest.php @@ -23,7 +23,7 @@ public function test_returns_response(): void ->with( ReCaptcha::SERVER_ENDPOINT, [ - 'secret' => ReCaptcha::TEST_V2_SECRET, + 'secret' => ReCaptcha::TEST_V2_SECRET, 'response' => 'token', 'remoteip' => '127.0.0.1', ] @@ -32,7 +32,7 @@ public function test_returns_response(): void ->andReturn( $this->fulfilledPromise([ 'success' => true, - 'foo' => 'bar', + 'foo' => 'bar', ]) ); @@ -67,7 +67,7 @@ public function test_uses_v2_test_credentials_by_default(): void ->with( ReCaptcha::SERVER_ENDPOINT, [ - 'secret' => ReCaptcha::TEST_V2_SECRET, + 'secret' => ReCaptcha::TEST_V2_SECRET, 'response' => 'token', 'remoteip' => '127.0.0.1', ] @@ -76,7 +76,7 @@ public function test_uses_v2_test_credentials_by_default(): void ->andReturn( $this->fulfilledPromise([ 'success' => true, - 'foo' => 'bar', + 'foo' => 'bar', ]) ); @@ -105,9 +105,9 @@ public function test_uses_v2_test_credentials_by_default(): void public function test_uses_v2_custom_credentials(): void { $this->app->make('config')->set('recaptcha.credentials', [ - 'checkbox' => ['secret' => 'secret-checkbox'], + 'checkbox' => ['secret' => 'secret-checkbox'], 'invisible' => ['secret' => 'secret-invisible'], - 'android' => ['secret' => 'secret-android'], + 'android' => ['secret' => 'secret-android'], ]); $mock = $this->mock(Factory::class); @@ -120,7 +120,7 @@ public function test_uses_v2_custom_credentials(): void ->with( ReCaptcha::SERVER_ENDPOINT, [ - 'secret' => 'secret-checkbox', + 'secret' => 'secret-checkbox', 'response' => 'token', 'remoteip' => '127.0.0.1', ] @@ -129,7 +129,7 @@ public function test_uses_v2_custom_credentials(): void ->andReturn( $this->fulfilledPromise([ 'success' => true, - 'foo' => 'bar', + 'foo' => 'bar', ]) ); @@ -137,7 +137,7 @@ public function test_uses_v2_custom_credentials(): void ->with( ReCaptcha::SERVER_ENDPOINT, [ - 'secret' => 'secret-invisible', + 'secret' => 'secret-invisible', 'response' => 'token', 'remoteip' => '127.0.0.1', ] @@ -146,7 +146,7 @@ public function test_uses_v2_custom_credentials(): void ->andReturn( $this->fulfilledPromise([ 'success' => true, - 'foo' => 'bar', + 'foo' => 'bar', ]) ); @@ -154,7 +154,7 @@ public function test_uses_v2_custom_credentials(): void ->with( ReCaptcha::SERVER_ENDPOINT, [ - 'secret' => 'secret-android', + 'secret' => 'secret-android', 'response' => 'token', 'remoteip' => '127.0.0.1', ] @@ -163,7 +163,7 @@ public function test_uses_v2_custom_credentials(): void ->andReturn( $this->fulfilledPromise([ 'success' => true, - 'foo' => 'bar', + 'foo' => 'bar', ]) ); @@ -210,7 +210,7 @@ public function test_receives_v3_secret(): void $mock->expects('withOptions')->with(['version' => 2.0])->once()->andReturnSelf(); $mock->expects('post') ->with(ReCaptcha::SERVER_ENDPOINT, [ - 'secret' => 'secret', + 'secret' => 'secret', 'response' => 'token', 'remoteip' => '127.0.0.1', ]) @@ -218,8 +218,8 @@ public function test_receives_v3_secret(): void ->andReturn( $this->fulfilledPromise([ 'success' => true, - 'score' => 0.5, - 'foo' => 'bar', + 'score' => 0.5, + 'foo' => 'bar', ]) ); @@ -247,7 +247,7 @@ public function test_http_factory_receives_config(): void $mock->expects('withOptions')->with(['foo' => 'bar'])->once()->andReturnSelf(); $mock->expects('post') ->with(ReCaptcha::SERVER_ENDPOINT, [ - 'secret' => 'secret', + 'secret' => 'secret', 'response' => 'token', 'remoteip' => '127.0.0.1', ])