Skip to content

Commit 1b46e91

Browse files
wip
1 parent 7e1751a commit 1b46e91

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

src/GoogleRecaptchaV3.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Support\Facades\Blade;
66
use Illuminate\Validation\Rule;
77
use Maize\GoogleRecaptchaV3\Enums\Badge;
8+
use Maize\GoogleRecaptchaV3\Rules\RecaptchaRule;
89
use Maize\GoogleRecaptchaV3\Support\Config;
910

1011
class GoogleRecaptchaV3
@@ -15,17 +16,19 @@ public function boot(): void
1516
$this->toHtml($badge)
1617
));
1718

18-
Rule::macro('googleRecaptchaV3', fn () => null);
19+
Rule::macro('googleRecaptchaV3', fn (?float $scoreThreshold = null) => (
20+
new RecaptchaRule($scoreThreshold)
21+
));
1922
}
2023

21-
protected function getJsScriptUrl(Badge $badge): string
24+
private function getJsScriptUrl(Badge $badge): string
2225
{
2326
return Config::getBaseJsScriptUrl()
2427
->withQuery(['badge' => $badge])
2528
->value();
2629
}
2730

28-
protected function getJsTokenScript(): string
31+
private function getJsTokenScript(): string
2932
{
3033
$key = Config::getSiteKey();
3134

@@ -54,7 +57,7 @@ protected function getJsTokenScript(): string
5457
JS;
5558
}
5659

57-
protected function toHtml(Badge $badge): string
60+
private function toHtml(Badge $badge): string
5861
{
5962
if (! Config::isEnabled()) {
6063
return '';
@@ -67,11 +70,6 @@ protected function toHtml(Badge $badge): string
6770
]);
6871
}
6972

70-
public function FunctionName($value = '')
71-
{
72-
// Rule::macro('recaptcha', );
73-
}
74-
7573
// <style>
7674
// .grecaptcha-badge {
7775
// bottom: 90px !important;

src/Rules/Recaptcha.php renamed to src/Rules/RecaptchaRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use Illuminate\Support\Facades\Http;
77
use Maize\GoogleRecaptchaV3\Support\Config;
88

9-
class Recaptcha implements ValidationRule
9+
class RecaptchaRule implements ValidationRule
1010
{
1111
public function __construct(
1212
private ?float $scoreThreshold = null

tests/RecaptchaRuleTest.php

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

33
use Illuminate\Support\Facades\Http;
4+
use Illuminate\Validation\Rule;
45
use Maize\GoogleRecaptchaV3\Rules\Recaptcha;
56

67
it('can validate token', function (bool $enabled, ?bool $success, ?float $score, ?float $threshold, bool $fails) {
@@ -27,7 +28,7 @@
2728

2829
$validator = validator(
2930
['token' => 'value'],
30-
['token' => new Recaptcha($threshold)]
31+
['token' => Rule::googleRecaptchaV3($threshold)]
3132
);
3233

3334
expect($validator->fails())->toBe($fails);

0 commit comments

Comments
 (0)