Skip to content

Commit 8ddf282

Browse files
committed
fixed cleancode
1 parent 9dce2d5 commit 8ddf282

File tree

4 files changed

+50
-28
lines changed

4 files changed

+50
-28
lines changed
Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
@if(\TimeHunter\LaravelGoogleReCaptchaV3\GoogleReCaptchaV3::$hasAction === false)
2-
@if($display === false)
3-
<style>
4-
.grecaptcha-badge {
5-
display: none;
6-
}
7-
</style>
8-
@endif
9-
<script>
10-
if (!document.getElementById('gReCaptchaScript')) {
11-
let reCaptchaScript = document.createElement('script');
12-
reCaptchaScript.setAttribute('src', 'https://www.google.com/recaptcha/api.js?render={{$publicKey}}');
13-
reCaptchaScript.async = true;
14-
reCaptchaScript.defer = true;
15-
document.head.appendChild(reCaptchaScript);
1+
@if($display === false)
2+
<style>
3+
.grecaptcha-badge {
4+
display: none;
165
}
17-
</script>
6+
</style>
187
@endif
8+
<script>
9+
if (!document.getElementById('gReCaptchaScript')) {
10+
let reCaptchaScript = document.createElement('script');
11+
reCaptchaScript.setAttribute('src', 'https://www.google.com/recaptcha/api.js?render={{$publicKey}}');
12+
reCaptchaScript.async = true;
13+
reCaptchaScript.defer = true;
14+
document.head.appendChild(reCaptchaScript);
15+
}
16+
</script>
17+

resources/views/googlerecaptchav3/template.blade.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
{{\TimeHunter\LaravelGoogleReCaptchaV3\GoogleReCaptchaV3::setHasAction(true)}}
21
<script>
32
43
function onloadCallback() {

src/GoogleReCaptchaV3.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,20 @@ class GoogleReCaptchaV3
1717
private $service;
1818
private $defaultTemplate = 'GoogleReCaptchaV3::googlerecaptchav3.template';
1919
private $defaultBackgroundTemplate = 'GoogleReCaptchaV3::googlerecaptchav3.background';
20-
2120
public static $hasAction = false;
2221

2322
public function __construct(GoogleReCaptchaV3Service $service)
2423
{
2524
$this->service = $service;
2625
}
2726

28-
/**
29-
* @param $value
30-
* @return bool
31-
*/
32-
public static function setHasAction($value)
33-
{
34-
self::$hasAction = $value;
35-
return self::$hasAction;
36-
}
37-
3827
/**
3928
* @param $mappers
4029
* @return array
4130
*/
4231
public function prepareViewData($mappers)
4332
{
33+
self::$hasAction = true;
4434
$prepareData = [];
4535
foreach ($mappers as $id => $action) {
4636
$prepareData[$action][] = $id;
@@ -72,6 +62,10 @@ public function prepareBackgroundData()
7262
*/
7363
public function background()
7464
{
65+
if(self::$hasAction){
66+
return;
67+
}
68+
7569
return app('view')
7670
->make(
7771
$this->getBackgroundView(),

tests/ViewTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,34 @@ public function testView2()
5757
$this->assertEquals(false, $data['inline']);
5858
$this->assertEquals('en', $data['language']);
5959
}
60+
61+
62+
public function testView3()
63+
{
64+
// Create a stub for the SomeClass class.
65+
$configStub = $this->createMock(ReCaptchaConfigV3::class);
66+
67+
// Configure the stub.
68+
$configStub->method('isServiceEnabled')
69+
->willReturn(true);
70+
71+
$configStub->method('getSiteKey')
72+
->willReturn('test1');
73+
74+
$configStub->method('isInline')
75+
->willReturn(false);
76+
77+
$configStub->method('getLanguage')
78+
->willReturn('en');
79+
80+
$clientStub = $this->createMock(GuzzleRequestClient::class);
81+
82+
$_service = new GoogleReCaptchaV3Service($configStub, $clientStub);
83+
$service = new GoogleReCaptchaV3($_service);
84+
85+
$service->prepareViewData(['contact_us_id' => 'contact_us']);
86+
$background = $service->background();
87+
$this->assertEquals('', $background);
88+
89+
}
6090
}

0 commit comments

Comments
 (0)