Skip to content

Commit 5d1c824

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents fb61e12 + a59c735 commit 5d1c824

File tree

7 files changed

+13
-31
lines changed

7 files changed

+13
-31
lines changed

src/Configurations/ReCaptchaConfigV2.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace TimeHunter\LaravelGoogleReCaptchaV2\Configurations;
44

5-
65
use TimeHunter\LaravelGoogleReCaptchaV2\Interfaces\ReCaptchaConfigV2Interface;
76

87
class ReCaptchaConfigV2 implements ReCaptchaConfigV2Interface

src/GoogleReCaptchaV2.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88

99
namespace TimeHunter\LaravelGoogleReCaptchaV2;
1010

11-
1211
use TimeHunter\LaravelGoogleReCaptchaV2\Core\GoogleReCaptchaV2Response;
13-
use TimeHunter\LaravelGoogleReCaptchaV2\Interfaces\ReCaptchaConfigV2Interface;
1412
use TimeHunter\LaravelGoogleReCaptchaV2\Services\GoogleReCaptchaV2Service;
13+
use TimeHunter\LaravelGoogleReCaptchaV2\Interfaces\ReCaptchaConfigV2Interface;
1514

1615
class GoogleReCaptchaV2
1716
{
@@ -35,15 +34,14 @@ public function __construct(GoogleReCaptchaV2Service $service)
3534
*/
3635
public function prepareViewData(...$ids)
3736
{
38-
3937
$data = [
4038
'publicKey' => $this->getConfig()->getSiteKey(),
4139
'ids' => $ids,
4240
'inline' => $this->getConfig()->isInline(),
4341
'language' => $this->getConfig()->getLanguage(),
4442
'theme' => $this->getConfig()->getTheme(),
4543
'badge' => $this->getConfig()->getBadge(),
46-
'size' => $this->getConfig()->getSize()
44+
'size' => $this->getConfig()->getSize(),
4745
];
4846

4947
return $data;
@@ -55,15 +53,14 @@ public function prepareViewData(...$ids)
5553
*/
5654
public function render(...$ids)
5755
{
58-
if (!$this->getConfig()->isServiceEnabled()) {
59-
return null;
56+
if (! $this->getConfig()->isServiceEnabled()) {
57+
return;
6058
}
6159
$data = $this->prepareViewData($ids);
6260

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

66-
6764
/**
6865
* @param $response
6966
* @param null $ip

src/Interfaces/ReCaptchaConfigV2Interface.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ public function getSiteKey();
3535
*/
3636
public function getOptions();
3737

38-
3938
/**
4039
* @return string
4140
*/

src/Providers/GoogleReCaptchaV2ServiceProvider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
use TimeHunter\LaravelGoogleReCaptchaV2\Core\GuzzleRequestClient;
99
use TimeHunter\LaravelGoogleReCaptchaV2\Configurations\ReCaptchaConfigV2;
1010
use TimeHunter\LaravelGoogleReCaptchaV2\Interfaces\RequestClientInterface;
11-
use TimeHunter\LaravelGoogleReCaptchaV2\Interfaces\ReCaptchaConfigV2Interface;
1211
use TimeHunter\LaravelGoogleReCaptchaV2\Services\GoogleReCaptchaV2Service;
12+
use TimeHunter\LaravelGoogleReCaptchaV2\Interfaces\ReCaptchaConfigV2Interface;
1313

1414
class GoogleReCaptchaV2ServiceProvider extends ServiceProvider
1515
{
@@ -73,6 +73,7 @@ public function register()
7373
}
7474
$this->app->bind('GoogleReCaptchaV2', function () {
7575
$service = new GoogleReCaptchaV2Service(app(ReCaptchaConfigV2Interface::class), app(RequestClientInterface::class));
76+
7677
return new GoogleReCaptchaV2($service);
7778
});
7879
}
@@ -89,10 +90,9 @@ protected function bootForConsole()
8990
__DIR__.'/../../config/googlerecaptchav2.php' => config_path('googlerecaptchav2.php'),
9091
], 'googlerecaptchav2.config');
9192

92-
9393
// Publishing the views.
9494
$this->publishes([
95-
__DIR__ . '/../../resources/views' => base_path('resources/views'),
95+
__DIR__.'/../../resources/views' => base_path('resources/views'),
9696
], 'googlerecaptchav2.views');
9797
}
9898

src/Services/GoogleReCaptchaV2Service.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Created by PhpStorm.
44
* User: dadeng
55
* Date: 2018/12/28
6-
* Time: 5:37 PM
6+
* Time: 5:37 PM.
77
*/
88

99
namespace TimeHunter\LaravelGoogleReCaptchaV2\Services;
@@ -14,7 +14,6 @@
1414

1515
class GoogleReCaptchaV2Service
1616
{
17-
1817
public $config;
1918
public $requestClient;
2019

@@ -36,7 +35,7 @@ public function __construct(ReCaptchaConfigV2Interface $config, RequestClientInt
3635
*/
3736
public function verifyResponse($response, $ip = null)
3837
{
39-
if (!$this->config->isServiceEnabled()) {
38+
if (! $this->config->isServiceEnabled()) {
4039
$res = new GoogleReCaptchaV2Response([], $ip);
4140
$res->setSuccess(true);
4241

@@ -71,14 +70,13 @@ public function verifyResponse($response, $ip = null)
7170
return $rawResponse;
7271
}
7372

74-
if (!empty($this->config->getHostName()) && strcasecmp($this->config->getHostName(), $rawResponse->getHostname()) !== 0) {
73+
if (! empty($this->config->getHostName()) && strcasecmp($this->config->getHostName(), $rawResponse->getHostname()) !== 0) {
7574
$rawResponse->setMessage(GoogleReCaptchaV2Response::ERROR_HOSTNAME);
7675
$rawResponse->setSuccess(false);
7776

7877
return $rawResponse;
7978
}
8079

81-
8280
$rawResponse->setSuccess(true);
8381
$rawResponse->setMessage('Successfully passed.');
8482

@@ -100,4 +98,4 @@ public function getRequestClient(): RequestClientInterface
10098
{
10199
return $this->requestClient;
102100
}
103-
}
101+
}

tests/ConfigTest.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
namespace TimeHunter\Tests\GoogleReCaptchaV2;
44

55
use PHPUnit\Framework\TestCase;
6-
use TimeHunter\LaravelGoogleReCaptchaV2\Core\GoogleReCaptchaV2Response;
76
use TimeHunter\LaravelGoogleReCaptchaV2\GoogleReCaptchaV2;
87
use TimeHunter\LaravelGoogleReCaptchaV2\Core\GuzzleRequestClient;
8+
use TimeHunter\LaravelGoogleReCaptchaV2\Core\GoogleReCaptchaV2Response;
99
use TimeHunter\LaravelGoogleReCaptchaV2\Configurations\ReCaptchaConfigV2;
1010
use TimeHunter\LaravelGoogleReCaptchaV2\Services\GoogleReCaptchaV2Service;
1111

@@ -43,7 +43,6 @@ public function testMissingInput()
4343
$clientStub->method('post')
4444
->willReturn(false);
4545

46-
4746
$_service = new GoogleReCaptchaV2Service($configStub, $clientStub);
4847
$service = new GoogleReCaptchaV2($_service);
4948

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

73-
7472
$_service = new GoogleReCaptchaV2Service($configStub, $clientStub);
7573
$service = new GoogleReCaptchaV2($_service);
7674

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

96-
9794
$_service = new GoogleReCaptchaV2Service($configStub, $clientStub);
9895
$service = new GoogleReCaptchaV2($_service);
9996

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

122-
123119
$_service = new GoogleReCaptchaV2Service($configStub, $clientStub);
124120
$service = new GoogleReCaptchaV2($_service);
125121

@@ -147,13 +143,11 @@ public function testHostName2()
147143
$clientStub->method('post')
148144
->willReturn($testJson);
149145

150-
151146
$_service = new GoogleReCaptchaV2Service($configStub, $clientStub);
152147
$service = new GoogleReCaptchaV2($_service);
153148

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

156151
$this->assertEquals(true, $response->isSuccess());
157152
}
158-
159153
}

tests/ViewTest.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ public function testView()
2121

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

24-
2524
$_service = new GoogleReCaptchaV2Service($configStub, $clientStub);
2625
$service = new GoogleReCaptchaV2($_service);
2726

@@ -49,7 +48,6 @@ public function testView2()
4948

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

52-
5351
$_service = new GoogleReCaptchaV2Service($configStub, $clientStub);
5452
$service = new GoogleReCaptchaV2($_service);
5553

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

64-
65-
6662
public function testView3()
6763
{
6864
// Create a stub for the SomeClass class.
@@ -83,11 +79,10 @@ public function testView3()
8379

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

86-
8782
$_service = new GoogleReCaptchaV2Service($configStub, $clientStub);
8883
$service = new GoogleReCaptchaV2($_service);
8984

90-
$data = $service->prepareViewData('contact_us_id','contact_us_id2');
85+
$data = $service->prepareViewData('contact_us_id', 'contact_us_id2');
9186

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

0 commit comments

Comments
 (0)