diff --git a/src/Services/GoogleReCaptchaV3Service.php b/src/Services/GoogleReCaptchaV3Service.php index 6a60816..9fdcad3 100644 --- a/src/Services/GoogleReCaptchaV3Service.php +++ b/src/Services/GoogleReCaptchaV3Service.php @@ -32,6 +32,7 @@ public function __construct(ReCaptchaConfigV3Interface $config, RequestClientInt public function ifInSkippedIps($ip) { $ips = $this->config->getSkipIps(); + return in_array($ip, $ips); } @@ -42,14 +43,13 @@ public function ifInSkippedIps($ip) */ public function verifyResponse($response, $ip = null) { - if (!$this->config->isServiceEnabled() || ($ip && $this->ifInSkippedIps($ip)) === true) { + if (! $this->config->isServiceEnabled() || ($ip && $this->ifInSkippedIps($ip)) === true) { $res = new GoogleReCaptchaV3Response([], $ip); $res->setSuccess(true); return $res; } - if (empty($response)) { $res = new GoogleReCaptchaV3Response([], $ip, GoogleReCaptchaV3Response::MISSING_INPUT_ERROR); $res->setSuccess(false); @@ -78,7 +78,7 @@ public function verifyResponse($response, $ip = null) return $rawResponse; } - if (!empty($this->config->getHostName()) && strcasecmp($this->config->getHostName(), $rawResponse->getHostname()) !== 0) { + if (! empty($this->config->getHostName()) && strcasecmp($this->config->getHostName(), $rawResponse->getHostname()) !== 0) { $rawResponse->setMessage(GoogleReCaptchaV3Response::ERROR_HOSTNAME); $rawResponse->setSuccess(false); diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 8c7460e..c9e83e0 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -221,8 +221,6 @@ public function testActionSkip() $this->assertEquals(true, $response->isSuccess()); } - - public function testIpSkip1() { // Create a stub for the SomeClass class. @@ -244,11 +242,10 @@ public function testIpSkip1() $_service = new GoogleReCaptchaV3Service($configStub, $clientStub); $service = new GoogleReCaptchaV3($_service); - $response = $service->verifyResponse('test response','1.1.1.1'); + $response = $service->verifyResponse('test response', '1.1.1.1'); $this->assertEquals(true, $response->isSuccess()); } - public function testIpSkip2() { // Create a stub for the SomeClass class. @@ -270,7 +267,7 @@ public function testIpSkip2() $_service = new GoogleReCaptchaV3Service($configStub, $clientStub); $service = new GoogleReCaptchaV3($_service); - $response = $service->verifyResponse('test response','1.1.1.2'); + $response = $service->verifyResponse('test response', '1.1.1.2'); $this->assertEquals(false, $response->isSuccess()); } }