Skip to content

Commit

Permalink
Apply fixes from StyleCI
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanDaDeng authored and StyleCIBot committed Dec 28, 2018
1 parent 1b4a6e9 commit ac802e7
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 31 deletions.
1 change: 0 additions & 1 deletion src/Configurations/ReCaptchaConfigV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace TimeHunter\LaravelGoogleReCaptchaV2\Configurations;


use TimeHunter\LaravelGoogleReCaptchaV2\Interfaces\ReCaptchaConfigV2Interface;

class ReCaptchaConfigV2 implements ReCaptchaConfigV2Interface
Expand Down
11 changes: 4 additions & 7 deletions src/GoogleReCaptchaV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@

namespace TimeHunter\LaravelGoogleReCaptchaV2;


use TimeHunter\LaravelGoogleReCaptchaV2\Core\GoogleReCaptchaV2Response;
use TimeHunter\LaravelGoogleReCaptchaV2\Interfaces\ReCaptchaConfigV2Interface;
use TimeHunter\LaravelGoogleReCaptchaV2\Services\GoogleReCaptchaV2Service;
use TimeHunter\LaravelGoogleReCaptchaV2\Interfaces\ReCaptchaConfigV2Interface;

class GoogleReCaptchaV2
{
Expand All @@ -35,15 +34,14 @@ public function __construct(GoogleReCaptchaV2Service $service)
*/
public function prepareViewData(...$ids)
{

$data = [
'publicKey' => $this->getConfig()->getSiteKey(),
'ids' => $ids,
'inline' => $this->getConfig()->isInline(),
'language' => $this->getConfig()->getLanguage(),
'theme' => $this->getConfig()->getTheme(),
'badge' => $this->getConfig()->getBadge(),
'size' => $this->getConfig()->getSize()
'size' => $this->getConfig()->getSize(),
];

return $data;
Expand All @@ -55,15 +53,14 @@ public function prepareViewData(...$ids)
*/
public function render(...$ids)
{
if (!$this->getConfig()->isServiceEnabled()) {
return null;
if (! $this->getConfig()->isServiceEnabled()) {
return;
}
$data = $this->prepareViewData($ids);

return app('view')->make($this->getConfig()->getTemplate(), $data);
}


/**
* @param $response
* @param null $ip
Expand Down
1 change: 0 additions & 1 deletion src/Interfaces/ReCaptchaConfigV2Interface.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public function getSiteKey();
*/
public function getOptions();


/**
* @return string
*/
Expand Down
6 changes: 3 additions & 3 deletions src/Providers/GoogleReCaptchaV2ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
use TimeHunter\LaravelGoogleReCaptchaV2\Core\GuzzleRequestClient;
use TimeHunter\LaravelGoogleReCaptchaV2\Configurations\ReCaptchaConfigV2;
use TimeHunter\LaravelGoogleReCaptchaV2\Interfaces\RequestClientInterface;
use TimeHunter\LaravelGoogleReCaptchaV2\Interfaces\ReCaptchaConfigV2Interface;
use TimeHunter\LaravelGoogleReCaptchaV2\Services\GoogleReCaptchaV2Service;
use TimeHunter\LaravelGoogleReCaptchaV2\Interfaces\ReCaptchaConfigV2Interface;

class GoogleReCaptchaV2ServiceProvider extends ServiceProvider
{
Expand Down Expand Up @@ -73,6 +73,7 @@ public function register()
}
$this->app->bind('GoogleReCaptchaV2', function () {
$service = new GoogleReCaptchaV2Service(app(ReCaptchaConfigV2Interface::class), app(RequestClientInterface::class));

return new GoogleReCaptchaV2($service);
});
}
Expand All @@ -89,10 +90,9 @@ protected function bootForConsole()
__DIR__.'/../../config/googlerecaptchav2.php' => config_path('googlerecaptchav2.php'),
], 'googlerecaptchav2.config');


// Publishing the views.
$this->publishes([
__DIR__ . '/../../resources/views' => base_path('resources/views'),
__DIR__.'/../../resources/views' => base_path('resources/views'),
], 'googlerecaptchav2.views');
}

Expand Down
10 changes: 4 additions & 6 deletions src/Services/GoogleReCaptchaV2Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Created by PhpStorm.
* User: dadeng
* Date: 2018/12/28
* Time: 5:37 PM
* Time: 5:37 PM.
*/

namespace TimeHunter\LaravelGoogleReCaptchaV2\Services;
Expand All @@ -14,7 +14,6 @@

class GoogleReCaptchaV2Service
{

public $config;
public $requestClient;

Expand All @@ -36,7 +35,7 @@ public function __construct(ReCaptchaConfigV2Interface $config, RequestClientInt
*/
public function verifyResponse($response, $ip = null)
{
if (!$this->config->isServiceEnabled()) {
if (! $this->config->isServiceEnabled()) {
$res = new GoogleReCaptchaV2Response([], $ip);
$res->setSuccess(true);

Expand Down Expand Up @@ -71,14 +70,13 @@ 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(GoogleReCaptchaV2Response::ERROR_HOSTNAME);
$rawResponse->setSuccess(false);

return $rawResponse;
}


$rawResponse->setSuccess(true);
$rawResponse->setMessage('Successfully passed.');

Expand All @@ -100,4 +98,4 @@ public function getRequestClient(): RequestClientInterface
{
return $this->requestClient;
}
}
}
8 changes: 1 addition & 7 deletions tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace TimeHunter\Tests\GoogleReCaptchaV2;

use PHPUnit\Framework\TestCase;
use TimeHunter\LaravelGoogleReCaptchaV2\Core\GoogleReCaptchaV2Response;
use TimeHunter\LaravelGoogleReCaptchaV2\GoogleReCaptchaV2;
use TimeHunter\LaravelGoogleReCaptchaV2\Core\GuzzleRequestClient;
use TimeHunter\LaravelGoogleReCaptchaV2\Core\GoogleReCaptchaV2Response;
use TimeHunter\LaravelGoogleReCaptchaV2\Configurations\ReCaptchaConfigV2;
use TimeHunter\LaravelGoogleReCaptchaV2\Services\GoogleReCaptchaV2Service;

Expand Down Expand Up @@ -43,7 +43,6 @@ public function testMissingInput()
$clientStub->method('post')
->willReturn(false);


$_service = new GoogleReCaptchaV2Service($configStub, $clientStub);
$service = new GoogleReCaptchaV2($_service);

Expand All @@ -70,7 +69,6 @@ public function testEmptyResponse()
$clientStub->method('post')
->willReturn($testJson);


$_service = new GoogleReCaptchaV2Service($configStub, $clientStub);
$service = new GoogleReCaptchaV2($_service);

Expand All @@ -93,7 +91,6 @@ public function testFalseResponse()
$clientStub->method('post')
->willReturn($testJson);


$_service = new GoogleReCaptchaV2Service($configStub, $clientStub);
$service = new GoogleReCaptchaV2($_service);

Expand All @@ -119,7 +116,6 @@ public function testHostName1()
$clientStub->method('post')
->willReturn($testJson);


$_service = new GoogleReCaptchaV2Service($configStub, $clientStub);
$service = new GoogleReCaptchaV2($_service);

Expand Down Expand Up @@ -147,13 +143,11 @@ public function testHostName2()
$clientStub->method('post')
->willReturn($testJson);


$_service = new GoogleReCaptchaV2Service($configStub, $clientStub);
$service = new GoogleReCaptchaV2($_service);

$response = $service->verifyResponse('test response');

$this->assertEquals(true, $response->isSuccess());
}

}
7 changes: 1 addition & 6 deletions tests/ViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public function testView()

$clientStub = $this->createMock(GuzzleRequestClient::class);


$_service = new GoogleReCaptchaV2Service($configStub, $clientStub);
$service = new GoogleReCaptchaV2($_service);

Expand Down Expand Up @@ -49,7 +48,6 @@ public function testView2()

$clientStub = $this->createMock(GuzzleRequestClient::class);


$_service = new GoogleReCaptchaV2Service($configStub, $clientStub);
$service = new GoogleReCaptchaV2($_service);

Expand All @@ -61,8 +59,6 @@ public function testView2()
$this->assertEquals('en', $data['language']);
}



public function testView3()
{
// Create a stub for the SomeClass class.
Expand All @@ -83,11 +79,10 @@ public function testView3()

$clientStub = $this->createMock(GuzzleRequestClient::class);


$_service = new GoogleReCaptchaV2Service($configStub, $clientStub);
$service = new GoogleReCaptchaV2($_service);

$data = $service->prepareViewData('contact_us_id','contact_us_id2');
$data = $service->prepareViewData('contact_us_id', 'contact_us_id2');

$this->assertEquals('test1', $data['publicKey']);
$this->assertEquals('contact_us_id', $data['ids'][0]);
Expand Down

0 comments on commit ac802e7

Please sign in to comment.