Skip to content

Commit

Permalink
Merge pull request #22 from RyanDaDeng/analysis-z9BQKl
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
RyanDaDeng authored Jan 25, 2019
2 parents 113bc1c + fbf4a71 commit 527ca08
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/Services/GoogleReCaptchaV3Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function __construct(ReCaptchaConfigV3Interface $config, RequestClientInt
public function ifInSkippedIps($ip)
{
$ips = $this->config->getSkipIps();

return in_array($ip, $ips);
}

Expand All @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
7 changes: 2 additions & 5 deletions tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,6 @@ public function testActionSkip()
$this->assertEquals(true, $response->isSuccess());
}



public function testIpSkip1()
{
// Create a stub for the SomeClass class.
Expand All @@ -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.
Expand All @@ -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());
}
}

0 comments on commit 527ca08

Please sign in to comment.